This conversion supports binary digits ranging from 0 to 32 bits, with the decimal number range from -2147483648 to -1.
Binary (base 2)
Decimal (base 10)
Hexadecimal (base 16)

Description

For the same number, the result of adding its negative and positive values should be 0. For example, for the number 7, -7 + 7 = 0, so -7 = 0 - 7, which can be represented in binary as -7 = 0000 - 0111 = 1001.

On the other hand, the binary representation of 7 is 0111. The one's complement of 0111 is 1000 and the two's complement (one's complement + 1) is 1001. Therefore, the binary representation of -7 is 1001, which matches the result obtained earlier.

From the perspective of the CPU, in an 8-bit data environment, a binary number like 11111001 can represent the decimal positive integer 249 or the decimal negative integer -7. Regardless of whether the CPU treats it as a positive or negative number during operations, the arithmetic results are always correct.

Signed integer encoding example
Decimal Binary Hexadecimal
-2147483648 10000000 00000000 00000000 00000000 80000000
-1073741824 11000000 00000000 00000000 00000000 C0000000
-536870912 11100000 00000000 00000000 00000000 E0000000
-268435456 11110000 00000000 00000000 00000000 F0000000
-134217728 11111000 00000000 00000000 00000000 F8000000
-67108864 11111100 00000000 00000000 00000000 FC000000
-33554432 11111110 00000000 00000000 00000000 FE000000
-16777216 11111111 00000000 00000000 00000000 FF000000
-8388608 11111111 10000000 00000000 00000000 FF800000
-4194304 11111111 11000000 00000000 00000000 FFC00000
-2097152 11111111 11100000 00000000 00000000 FFE00000
-1048576 11111111 11110000 00000000 00000000 FFF00000
-524288 11111111 11111000 00000000 00000000 FFF80000
-262144 11111111 11111100 00000000 00000000 FFFC0000
-131072 11111111 11111110 00000000 00000000 FFFE0000
-65536 11111111 11111111 00000000 00000000 FFFF0000
-32768 11111111 11111111 10000000 00000000 FFFF8000
-16384 11111111 11111111 11000000 00000000 FFFFC000
-8192 11111111 11111111 11100000 00000000 FFFFE000
-4096 11111111 11111111 11110000 00000000 FFFFF000
-2048 11111111 11111111 11111000 00000000 FFFFF800
-1024 11111111 11111111 11111100 00000000 FFFFFC00
-512 11111111 11111111 11111110 00000000 FFFFFE00
-256 11111111 11111111 11111111 00000000 FFFFFF00
-128 11111111 11111111 11111111 10000000 FFFFFF80
-64 11111111 11111111 11111111 11000000 FFFFFFC0
-32 11111111 11111111 11111111 11100000 FFFFFFE0
-16 11111111 11111111 11111111 11110000 FFFFFFF0
-8 11111111 11111111 11111111 11111000 FFFFFFF8
-4 11111111 11111111 11111111 11111100 FFFFFFFC
-2 11111111 11111111 11111111 11111110 FFFFFFFE
-1 11111111 11111111 11111111 11111111 FFFF FFFF

0 Comments

0 / 300