如何将unsigned char转换为byte [英] how to convert an unsigned char to byte

查看:141
本文介绍了如何将unsigned char转换为byte的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道char是2个字节,转换就像

byte [] byte_array = new byte [2 * char_length]; //分配双重记忆为

char的原因

然后为每个char做

byte [0] =(byte)char [0] &安培; 0xff

byte [1] =(byte)(char [0]>> 8& 0xff)


一个unsigned char是1个字节,谁能告诉我转换

方法?


非常感谢你!

I know a char is 2 bytes, the conversion is like
byte[] byte_array = new byte[2*char_length]; //Allocate double mem as
that of char
then for each char do
byte[0] = (byte) char[0] & 0xff
byte[1] = (byte)( char[0] >> 8 & 0xff)

one unsigned char is 1 byte, could anyone tell me the conversion
method?

Thank you very much!

推荐答案

" QQ" <菊**** @ yahoo.com>在新闻中写道:1127927753.715838.327590

@ o13g2000cwo.googlegroups.com:
"QQ" <ju****@yahoo.com> wrote in news:1127927753.715838.327590
@o13g2000cwo.googlegroups.com:
我知道char是2个字节,


在C中,sizeof(char)始终为1.

转换类似于
byte [] byte_array = new byte [2 * char_length];
I know a char is 2 bytes,
In C, sizeof(char) is always 1.
the conversion is like
byte[] byte_array = new byte[2*char_length];




您是否认为自己是Java小组?


思南

-

A. Sinan Unur< 1u ** @ llenroc.ude.invalid>

(反转每个组件并删除.invalid for email address)



Are you under the impression that you are in a Java group?

Sinan
--
A. Sinan Unur <1u**@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)


QQ写道:
我知道char是2个字节,


char是1字节的定义。从错误的

前提下来的任何事情都是假的,或者只是运气真实。

转换就像
byte [] byte_array = new byte [2 * char_length ]。 //将$ mem分配为


上述行 - 除了使用C ++启发的语法错误

''new'' - make没有任何意义。

如果有一个类型''byte''(没有),

byte_array的声明看起来像

byte byte_array [2 * char_length];

当然标识符''char_length''只是为了混淆。如果

char_length == sizeof(char),那么它应该省略,因为它是由

定义的1。否则,它需要一个新名称。

那个char
然后为每个char做
byte [0] =(byte)char [0]& 0xff


不仅没有类型''byte'',你使用''byte''作为

变量的名称,作为假定的类型。此外,您使用

实际类型''char''的名称作为变量的名称。当你在场景中散布这种错误的
代币时,你可以找到通往键盘的方式,这是一个奇迹。

byte [1 ] =(byte)(char [0]>> 8& 0xff)

一个unsigned char是1个字节,有人能告诉我转换方法吗?


再试一次。下次花费至少足够的时间来问一个连贯的问题。

非常感谢!
I know a char is 2 bytes,
A char is 1 byte by definition. Anything following from your incorrect
premise is either false or only true by luck.
the conversion is like
byte[] byte_array = new byte[2*char_length]; //Allocate double mem as
the above line -- apart from its use of the C++-inspired syntax error
''new'' -- makes no sense.
If there were a type ''byte'' (which there isn''t), a declaration of
byte_array would look like
byte byte_array[2 * char_length];
Of course the identifier ''char_length'' is meant only to confuse. If
char_length == sizeof(char), then it should be omitted, since it is 1 by
definition. Otherwise, it needs a new name.
that of char
then for each char do
byte[0] = (byte) char[0] & 0xff
Not only is there no type ''byte'', you are using ''byte'' as the name of a
variable and as a putative type. Further, you are using the name of an
actual type ''char'' as the name of a variable. It is a wonder that you
can find your way to the keyboard when you strew such misdirecting
tokens over the landscape.
byte[1] = (byte)( char[0] >> 8 & 0xff)

one unsigned char is 1 byte, could anyone tell me the conversion
method?
Try again. Next time spend at least enough time to ask a coherent question.
Thank you very much!



QQ写道:
我知道char是2个字节,转换就像


不在C中它不是。在C中,char是1字节的定义,尽管
字节可以超过8位。

byte [] byte_array = new byte [2 * char_length]; //分配双重记忆为
I know a char is 2 bytes, the conversion is like
Not in C it isn''t. In C a char is 1 byte by definition, although that
byte can be more than 8 bits.
byte[] byte_array = new byte[2*char_length]; //Allocate double mem as




< snip>


以上不是C.可能是C ++(comp .lang.c ++是新闻组

隔壁)但我相信在C ++中,char也是1字节的定义。

-

Flash Gordon

生活在有趣的时代。

虽然我的电子邮件地址说垃圾邮件,但这是真实的,我读了它。



<snip>

The above is not C. It could be C++ (comp.lang.c++ is the news group
next door) but I believe that in C++ a char is 1 byte by definition as well.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.


这篇关于如何将unsigned char转换为byte的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆