How to use the Binary Two's complement hex Converter tool
- Enter the signed pattern in the Binary word box. Type every bit of the word, since the first digit is taken as the sign bit.
- Select Convert to read the word.
- Read the Hex line and the Signed decimal line in the Result box.
- Select Copy to copy both lines, or Example to try 11010111.
Two views of the same signed word
Hexadecimal has no notion of sign. It is a shorter spelling of the bits, four at a time. A debugger that shows FFFFFFFE is showing 32 raw bits, and it is up to the reader to know the variable is a signed int holding -2.
This tool makes both readings explicit. The Hex line is the bit pattern in uppercase hex. The Signed decimal line interprets the same pattern as a two's complement integer whose width is the number of bits you entered.
Worked example: 11010111 as hex and signed decimal
Split the sample into nibbles: 1101 is D and 0111 is 7, so the hex is D7. For the signed value, the pattern as an unsigned number is 215. The top bit is 1, so subtract 2^8: 215 - 256 = -41.
The same value at 16 bits is 1111111111010111, which the tool reports as FFD7 and -41. Widening a negative number fills the new high bits with ones, and those appear as leading F digits.
11010111
Hex: D7
Signed decimal: -41
1111111110000000
Hex: FF80
Signed decimal: -128Widths that are not a multiple of four
The hex output has one digit for every four bits, rounded up, and the missing high bits of the first digit are filled with zeros, not with copies of the sign bit. The 6-bit word 110100 is -12, and its hex is 34.
Be careful when carrying such a result elsewhere: read as an 8-bit value, 34 is +52. If the hex has to keep the sign at a byte boundary, sign-extend the word before converting. Entering 11110100 gives F4 and -12.
Accepted input
The field takes binary only. To start from hex digits, expand them with the Hexadecimal to Binary tool first.
- Between 1 and 65,536 bits, using the characters 0 and 1.
- Spaces and line breaks are ignored, so nibble-grouped input such as 1111 1111 1111 1110 works.
- A single 0b prefix at the start is removed.
- Leading zeros count toward the width and appear in the hex. 00101 gives 05 and the value 5.
- A leading 0 always means zero or positive, and a leading 1 always means negative.
Reading negative hex values yourself
For a full-width word, the first hex digit tells the sign: 0 to 7 means the top bit is clear, 8 to F means it is set and the value is negative. To get the magnitude, subtract the unsigned value from 2^n. For FF80 at 16 bits, 65,536 - 65,408 = 128, so the value is -128.
Frequently asked questions
What is FF in two's complement?
As an 8-bit word, FF is 11111111 and represents -1. Enter those eight bits and the tool shows Hex: FF and Signed decimal: -1. At 16 bits the same value is FFFF.
Why is there no minus sign in the hex output?
The Hex line shows the stored bits, and stored bits have no sign character. The sign is encoded in the top bit. The Signed decimal line is where the negative value is written out.
Can I enter a hexadecimal number instead of binary?
No. The Binary word box accepts only 0 and 1. Convert your hex to bits first, keeping all leading zeros so the word width stays correct.
How does the word width affect the signed decimal value?
The first bit entered is the sign bit. 1001 is a 4-bit word and reads as -7, while 00001001 is an 8-bit word and reads as 9. The hex digits change from 9 to 09.
How is this different from the Binary to Hexadecimal tool?
That tool converts an unsigned number and drops leading zeros. This one keeps the full width in the hex digits and adds the two's complement signed reading of the same bits.