what is output ??

Vishy Karl
Ranch Hand
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 ?

dennis zined
Ranch Hand
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
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 ]

Vishy Karl
Ranch Hand
Posts: 116
Thanks dennis for the explanation.

dennis zined
Ranch Hand
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.