31 in binary
The decimal number 31 written in binary is 11111. In hexadecimal it is 1F, and in octal 37.
| Base | Value |
|---|---|
| Decimal (base 10) | 31 |
| Binary (base 2) | 11111 |
| Hexadecimal (base 16) | 1F |
| Octal (base 8) | 37 |
How 31 converts to binary
Binary is base 2, so each place is worth twice the one to its right: 1, 2, 4, 8, 16, and so on. Adding up the place values that have a 1 gives back the decimal number:
16 + 8 + 4 + 2 + 1 = 31
That is why 31 in decimal is 11111 in binary: it is exactly the set of powers of two that add up to 31. To get the hexadecimal form, group the bits into fours from the right and write each group as one hex digit, which gives 1F.
Divide by 2: the method by hand
Divide 31 by 2 again and again and write down each remainder. The remainders, read from the last one back to the first, are the binary digits:
| Step | Division | Remainder (bit) |
|---|---|---|
| 1 | 31 / 2 = 15 | 1 |
| 2 | 15 / 2 = 7 | 1 |
| 3 | 7 / 2 = 3 | 1 |
| 4 | 3 / 2 = 1 | 1 |
| 5 | 1 / 2 = 0 | 1 |
Reading the remainders upward gives 11111.
31 in other codes
| Form | Value |
|---|---|
| 8-bit binary (padded) | 0001 1111 |
| Bits needed | 5 |
| BCD (each decimal digit in 4 bits) | 0011 0001 |
| Gray code (n XOR n shifted right) | 10000 |
| -31 in 8-bit two's complement | 1110 0001 |
BCD stores each decimal digit separately, as built in the decimal to BCD encoder; Gray code changes one bit between neighbours, as in the binary to Gray converter circuit. Negative numbers are stored in two's complement.
Convert any number
Type any value and watch all three bases update live in the binary converter, or read the theory behind it in the lessons on binary numbers and hexadecimal. To practice converting in your head, play the binary game.
Want to build the circuit that does this? Open the lab and wire up an adder, or follow the guided course from a single transistor up to an 8-bit CPU, starting with Act I for free.
Open the binary converter →Frequently asked
What is 31 in binary?
31 in binary is 11111. That is the sum of the powers of two 16 + 8 + 4 + 2 + 1, which add up to 31.
What is 31 in hexadecimal?
31 in hexadecimal is 1F. You get it by grouping the binary digits 11111 into fours from the right and writing each group as one hex digit.
How many bits is 31?
31 needs 5 bits in binary (11111). It fits in a single 8-bit byte.