42
42
101010
42 = 32 + 8 + 2, so the bits for 32, 8 and 2 are 1 and the others are 0.
Type a whole number and read it in binary, with each division by 2 shown underneath. It opens on 42, which is 101010.
Last updated
Coddy teaches you by writing real code in your browser - interactive lessons, instant feedback, and AI help when you get stuck.
Every division by 2 leaves a remainder of 0 or 1, and that remainder is the next bit, starting from the right. For 42: 42 ÷ 2 = 21 remainder 0, 21 ÷ 2 = 10 remainder 1, 10 ÷ 2 = 5 remainder 0, 5 ÷ 2 = 2 remainder 1, 2 ÷ 2 = 1 remainder 0 and 1 ÷ 2 = 0 remainder 1. Read upward, the remainders give 101010.
A second method works well for small numbers: find the largest power of 2 that fits (32 for 42), subtract it and repeat with what is left (10, then 8, then 2). Put a 1 under each power you used and a 0 under the others.
The converter shows the division method for any whole number you type and uses BigInt, so large values stay exact.
42
101010
42 = 32 + 8 + 2, so the bits for 32, 8 and 2 are 1 and the others are 0.
255
11111111
255 is one less than 256, so every bit below 256 is set: eight 1s.
192
11000000
192 = 128 + 64. Subnet masks such as 255.255.255.192 are read one byte at a time like this.
1024
10000000000
1024 is 2¹⁰, so it is a 1 followed by ten 0s.
bin(42) returns '0b101010', and format(42, 'b') returns '101010' without the prefix. In JavaScript, use (42).toString(2).