Decimal to binary
By Oakgen Team · Updated
Divide the number by 2 repeatedly and read the remainders from last to first. For 37: 37 ÷ 2 = 18 r 1, 18 ÷ 2 = 9 r 0, 9 ÷ 2 = 4 r 1, 4 ÷ 2 = 2 r 0, 2 ÷ 2 = 1 r 0, 1 ÷ 2 = 0 r 1, so 37 is 100101.
Decimal to Binary
Binary
| Decimal | Binary |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 10 |
| 3 | 11 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
| 8 | 1000 |
| 9 | 1001 |
| 10 | 1010 |
| 11 | 1011 |
| 12 | 1100 |
| 13 | 1101 |
| 14 | 1110 |
| 15 | 1111 |
| 16 | 10000 |
Divide by 2, read upward
Binary is base 2, so every digit is a bit: 0 or 1. Divide the number by 2, keep the remainder as the next bit from the right, and continue with the quotient until it reaches 0.
For 37 the remainders from first to last are 1, 0, 1, 0, 0, 1. Read from the last to the first, that is 100101. Check by place values: 32 + 4 + 1 = 37.
How many bits do you need?
A value fits in n bits when it is at most 2^n − 1. NIST defines a bit as a binary digit and a byte as a sequence of eight bits, so a byte holds 0 to 255 (2^8 − 1).
- 8 bits: 0 to 255 (11111111)
- 16 bits: 0 to 65,535
- 32 bits: 0 to 4,294,967,295
Leading zeros and negatives
The result has no leading zeros, but fixed-width data keeps them: 5 is 101, and as one byte it is 00000101. This converter takes whole numbers of 0 or more; negative numbers need a signed format such as two's complement, which depends on the bit width.
Do more with Oakgen Agent
The Agent can convert a list in its code sandbox, pad to the bit width you want, and return a table or CSV.
Open in Oakgen AgentThe prompt is filled in for you. Nothing is sent until you press send in the Agent.
FAQ
What is 10 in binary?
Decimal 10 is 1010: 8 + 2.
What is the binary for 255?
255 is 11111111, eight ones, the largest value of one byte.
How do I convert binary back to decimal?
Add the place values of the 1s. 100101 is 32 + 4 + 1 = 37. The Swap button above does this for you.
Why do computers use binary?
Binary has two digits, so each bit is a 0 or a 1. Hex and decimal are other ways for people to write the same values.