decimal convert

Quick question.

did I convert this correctly, the decimal form of -254 is converted to
11111111 11111111 11111111 11111101 in binary and ff ff ff 02 in hex?
Binary 11111101 could never be 0x02. Recheck.
No.

The binary one is -2.
The hex one is correct.
11111111 11111111 11111111 00000010, right?
Yeah.
BTW, calc.exe (or kcalc) can do this for you.
ok, but that does not help when I am converting binary to decimal since 11111111 11111111 11111111 00000010 is converted to the decimal form of 18446744073709551362. is there a way that I can check this? I want to check my homework before I turn it in.
When you do that, simply NOT the number and add 1, then convert to decimal and invert the sign.
Example:
Negative number (bit 31 is set):
11111111 11111111 11111111 00000010
NOT:
00000000 00000000 00000000 11111101
+1:
00000000 00000000 00000000 11111110
To base 10:
254
Sign inversion:
-254

Positive number (bit 31 is not set):
01111111 11111111 11111111 00000010
To base 10:
2147483394
ok, That makes sense. New question how do I convert decimal to IEEE 32- floating point ?
You'll need a hex editor for that, but you can also do this:
1
2
3
float a=/*...*/;
uint32_t b=*(uint32_t *)&x;
float c=*(float *)&b;

Of course, this won't work for doubles.
Topic archived. No new replies allowed.