| Author |
what is output ??
|
Vishy Karl
Ranch Hand
Joined: Sep 08, 2003
Posts: 116
|
|
Hi again, I really get confused with the following hexadecimal questions.What should I do to solve the folloing code?? just let me know what to do to solve this problem ? thanx in advance.
|
"The man who can drive himself further once the effort gets painful is the man who will win." <br />Roger Bannister
|
 |
dennis zined
Ranch Hand
Joined: Mar 07, 2003
Posts: 330
|
|
Convert 0xffffffc9 to binary - to easily convert hex to binary, each hex digit is converted: 1111 1111 1111 1111 1111 1111 1100 1001 Converting to byte lops of high order bits - high order bits removed : 1100 1001 - Using Two's complement: - flip the bits: 110110 = 54 - Add 1: 55 - Since leftmost digit is 1 (when high order bits were removed), value is negative: -55 Expression should now be: 1. b += b - (i = -55); 2. b += b - (-55); 3. b += b + 55; 4. b = 0 + 55; 5. b = 55 6. Converting to hex: 37 [ December 08, 2003: Message edited by: dennis zined ] [ December 08, 2003: Message edited by: dennis zined ]
|
SCJP 1.4<br />SCWCD 1.4
|
 |
Vishy Karl
Ranch Hand
Joined: Sep 08, 2003
Posts: 116
|
|
Thanks dennis for the explanation.
|
 |
dennis zined
Ranch Hand
Joined: Mar 07, 2003
Posts: 330
|
|
You're welcome. By the way when casting the int to byte, after the 24 high-order bits were discarded...you only do two's complement if the leftmost digit is 1. If it is 0, you can immediately convert to decimal and proceed with the math expression.
|
 |
 |
|
|
subject: what is output ??
|
|
|