Convert decimal to binary
To convert a decimal value into binary, divide the value by 2 and keep the remainder.
Repeat the division until the quotient is 0.
Read the remainders from the last one to the first one.
Try it
The value 300 in a 16-bit register. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·,
Binary
0b
0b0000000100101100
Hex
0x
0x012C
Decimal
300
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·,
Shift
Sign
Bits
Endian
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Worked example
Convert 300 into binary:
- 300 divided by 2 is 150, remainder 0.
- 150 divided by 2 is 75, remainder 0.
- 75 divided by 2 is 37, remainder 1.
- 37 divided by 2 is 18, remainder 1.
- 18 divided by 2 is 9, remainder 0.
- 9 divided by 2 is 4, remainder 1.
- 4 divided by 2 is 2, remainder 0.
- 2 divided by 2 is 1, remainder 0.
- 1 divided by 2 is 0, remainder 1.
- Read the remainders backwards: 100101100.
Where this is used
A binary form shows which bits have the value 1. A decimal form hides them.
A register value is easier to check in binary, because each bit is a separate flag.
Points to note
- The value 300 needs 9 bits. A register uses 8, 16, 32 or 64 bits, so the value goes into a 16-bit register.
- Zeros at the left do not change the value. The bit width sets how many of them appear.
- A negative decimal value needs a signed register. Use two’s complement for the negative form.
The full tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- What is 300 in binary?
- The value 300 is 100101100 in binary. In a 16-bit register it appears as 0000000100101100.
- How many bits do I need?
- Count the digits of the binary result. The value 300 gives 9 digits, so it needs at least 9 bits.
- Can I convert a negative value?
- Yes. Set the register to a signed mode. The negative value then uses two’s complement.