整数到十六进制字符串“&” ? [英] Integer to hex string "&" ?
问题描述
嗨..
我见过类似Integer.toHexString(i&0xff);的方法。 (我是最初声明的整数)。
我想知道&和0xff的部分是什么?
这是&表现得像+或其他什么?
括号之间运行的计算是什么?我的意思是(整数值和十六进制值)的行为......
我想我已经充分描述了我的问题..
提前致谢!
Hi..
I've seen a method like "Integer.toHexString(i & 0xff);" (i is an initially declared integer).
I wonder what part does the "&" and "0xff" take ?
Does this "&" act like the "+" or something else ?
And what's the computing that has been ran between the brackets ? I mean the behavior of (integer value & hexadecimal value)...
I think I've sufficiently described my problem..
Thanks in advance !
推荐答案
&
是按位AND
运算符。
0xff
是二进制<$的十六进制表示 c $ c> 11111111 (小数255
)。
因此:
(i& 0xff)
从整数i
中提取最不重要的字节。
&
is the bitwiseAND
operator.
0xff
is the hexadecimal representation of binary11111111
(decimal255
).
Hence:
(i & 0xff)
extracts the least significative byte from integer numberi
.
'&'的行为类似'+',因为它是一个运算符 - 但它有不同的功能。
这是一个二进制AND运算符:所以它适用于输入数字的各个位来生成一个结果。
对于每一位,它计算出结果将独立的结果 - 如果两个输入位都是1则产生1而对于所有其他组合则产生0:
'&' acts like '+' in that it's an operator - but it does a different function.
It's a Binary AND operator: so it works on individual bits of the input numbers to generate a result.
For each bit it works out what the result will be independently - it generates a "1" if both input bits are "1" and a "0" for all other combinations:
A B A&B
0 0 0
0 1 0
1 0 0
1 1 1
0xFF略有不同 - 它是一个常数值,但是而不是十进制(你通常使用的基数10)它是十六进制 - 基数16.
在基数10中你有十位数:
0xFF is slightly different - it's a constant value, but instead of being in Decimal (the base 10 that you normally use) it's an Hexadecimal - base 16.
In base 10 you have ten digits:
0 1 2 3 4 5 6 7 8 9
在基地16中,惊喜(惊喜!)十六:
In Base 16 that ere (surprise!) sixteen:
0 1 2 3 4 5 6 7 8 9 A B C D E F
所以0xFF或0xff(它们是相同的值)与基数10中的255相同,但很多更容易想象成二进制数字 - 11111111在基数2.
所以我& 0xff只是 i的底部八位
这篇关于整数到十六进制字符串“&” ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!