I have found something like that in the web : arrayOfByte[0] = (byte)((paramShort & 0xFF00) >>> 8);
What does this mean (0xFF00)?

- 60,010
- 15
- 145
- 220

- 45
- 1
- 2
- 3
-
1http://en.wikipedia.org/wiki/Hexadecimal#Written_representation – Marc B Jun 13 '14 at 18:29
-
It's an integer literal. – Sotirios Delimanolis Jun 13 '14 at 18:29
-
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html – Reinstate Monica -- notmaynard Jun 13 '14 at 18:30
-
The same as (paramShort & 65280). – Steffen Jun 13 '14 at 18:32
-
Also see http://stackoverflow.com/questions/243712/why-use-hex?lq=1 , http://stackoverflow.com/questions/2670639/why-are-hexadecimal-prefixed-as-0x?rq=1 , http://stackoverflow.com/questions/3437310/differences-between-0x01-and-0x01f?rq=1 – user2864740 Jun 13 '14 at 18:34
-
Aaaaaaaaah okay thx a lot :) And how can i understand this type of representation or is there any good tutorial to learn it ?? – patrick.morgan.csm Jun 13 '14 at 18:36
-
3By the way, this code is nonsense. A simple `arrayOfByte[0] = (byte)(paramShort>>>8)` would do the same… – Holger Jun 13 '14 at 18:43
1 Answers
0XFF00
is hexidecimal. This is a base-16 system where numbers go from 0-9
, then A-F
. This signifies going from 0 to 15 in our numbering system (base 10). 10
is actually 16 in base 10, followed by 11
which is 17 and so on. Hexidecimal is also called base 16.
Each character you see there is represented as 4-bits as we require 4 bits to represent a single hex number in base 16. As such, you can decompose each character in 4 bits. Assuming this is in big-endian, your number is:
0xFF00 ==>
F - 1111
F - 1111
0 - 0000
0 - 0000
As such, in binary your number is actually:
1111 1111 0000 0000
Bear in mind this is a 16-bit or 2-byte number. Converting from binary to decimal gives you a decimal number of 65280. In any case, with respect to your code, paramShort
is 2 bytes. What you are doing is you are masking out the lower byte of your number, then bit-shifting all of the bits to the right by 8. Essentially, what you are doing is grabbing the most significant byte of your number and seeing what that is.
However, masking out using 0xFF00
is a bit superfluous in my opinion. You can simply just bit shift to the right by 8 and as you are bit shifting to the right, the left bits should get filled in with zeroes, so you are effectively doing the same thing by just bitshifting. I'm guessing the masking is there to ensure the reader that extracting the MSB is the intended operation.
Hope this helps.

- 102,964
- 22
- 184
- 193
-
1If you are new to the game, you probably won't understand rayryeng's answer. I would advice newcomers to read the following articles to truly get the grasp of what hexidecimal is: [khan academy](https://www.khanacademy.org/computing/ap-computer-science-principles/computers-101/digital-data-representation/a/digital-data-introduction) – Sebastian Nielsen Jun 08 '19 at 20:05