Originally posted by Yin Ming:
hi all:
Java treat the 0x91 as a -111 and fills the high 24 bits with 1.(0xffffff91) so :
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by ravish kumar:
Hi
Why 0x91 is treated as -111 ??
Thanks in advance
Originally posted by Yin Ming:
try this:
<code>byte b=(byte)0x91;
System.out.println(b);<code>
0x91 = 10010001
this is the binary form of -111.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by Yin Ming:
hi all:
I read RHE and met the problem: how to shift a unsigned binary byte?
10010001byte buf=0x91;
1111111..110010001integal promotion, buf to int
0111111..111001000right shift 1 bit
11001000cast to byte.
this is what I expect:
10010001a unsigned binary byte
01001000after right shift
what can I do if I must deal with 8bits data?
Originally posted by ravish kumar:
Hi Yen
Thanks!! but I wanted to know why after integral promotion 0x91 becomes 0xffffff91 instead of 0x00000091.
Thanks in advance
sorry , becoz my badly speaking in English, I cannot explain it clearly. the binary form of 0x91 is :
10010001
U see the highest bit is 1. this is where the negative sign sits. Java thinks that it's a negative number so parses it as a -111. then why does the -111 represent 10010001? its not easy to explain, let me have a try:
the binary form of negative is calculated by these step:
1.first, the positive 111's bit pattern is: 01101111
2.then do the binary not: ~01101111=10010000
3.add 1: 10010000+1=10010001. this is the binary form of -111
this is a fundamental subject of computer. hope this can help
Originally posted by Yin Ming:
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
Originally posted by ravish kumar:
I think the only type which is unsigned is 'char'.
so there is nothing like "unsigned byte".
CMIW
Originally posted by ravish kumar:
byte buf = 0x91;
internally it should be stored as 0x00000091, as 0x91 is positive number(I think only negative numbers are stored in 2's compliment form, CMIW).
Now when we apply shift operation on 'buf' which is stored as 0x00000091 so it should give desired result.
Thanks in advance again.
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh
"Thanks to Indian media who has over the period of time swiped out intellectual taste from mass Indian population." - Chetan Parekh