clea.patlecxerm
New Member
- Joined
- Jun 5, 2012
- Messages
- 6
Hi,
I had used the DEC2HEX to convert a column of decimal numbers anywhere from 0 to 1023. It was ok and I got values from 000 to 3FF corresponding to 0000 0000 0000 and 0011 1111 1111 in binary. My problem now is when it is from -1 to -1023. The values I got are from FFFFFFFFFF to FFFFFFFC01.
Instead of this number: I should get, 401 to 7FF. In binary: 0100 0000 0001 to 0111 1111 1111.
The 11th bit will serve as the sign bit.
DEC HEX BINARY
0 000 0000 0000 0000 (ZERO)
+1 001 0000 0000 0001 (0 as the 11th bit means positive)
-1 401 0100 0000 0001 (1 as the 11th bit means a negative)
+1023 3FF 0011 1111 1111 (+ sign bit)
-1023 7FF 0111 1111 1111 (- sign bit)
For both positive and negative decimal number, I was thinking of getting the absolute value first, convert via DEC2HEX then just change the 11th bit according to the sign.
Your ideas will be greatly appreciated.
Thank you.
I had used the DEC2HEX to convert a column of decimal numbers anywhere from 0 to 1023. It was ok and I got values from 000 to 3FF corresponding to 0000 0000 0000 and 0011 1111 1111 in binary. My problem now is when it is from -1 to -1023. The values I got are from FFFFFFFFFF to FFFFFFFC01.
Instead of this number: I should get, 401 to 7FF. In binary: 0100 0000 0001 to 0111 1111 1111.
The 11th bit will serve as the sign bit.
DEC HEX BINARY
0 000 0000 0000 0000 (ZERO)
+1 001 0000 0000 0001 (0 as the 11th bit means positive)
-1 401 0100 0000 0001 (1 as the 11th bit means a negative)
+1023 3FF 0011 1111 1111 (+ sign bit)
-1023 7FF 0111 1111 1111 (- sign bit)
For both positive and negative decimal number, I was thinking of getting the absolute value first, convert via DEC2HEX then just change the 11th bit according to the sign.
Your ideas will be greatly appreciated.
Thank you.