Binary Calculator
42 (decimal) =
Solution Details
- 42 (base 10) = 101010 (base 2)
- Hex: 2a Octal: 52 Bits: 6
- Final answer: 101010₂
- Decimal (base 10):
- 42
- Hex (base 16):
- 0x2a
- Octal (base 8):
- 52
- Bit length:
- 6 bits
Convert a non-negative integer in base 10 to its binary (base 2) representation. Repeatedly divide by 2 and read the remainders bottom-up to get the bit pattern.
decimal n → binary by repeated division by 2
Convert a binary number to base 10 by multiplying each bit by its place value (a power of 2) and adding the results.
binary b → decimal by sum of bit × 2ⁿ
Add two binary numbers digit by digit from right to left, carrying a 1 to the next column whenever the column sum reaches 2.
a + b (base 2, with carries)
Subtract two binary numbers digit by digit from right to left, borrowing from the next column whenever the top bit is smaller than the bottom bit.
a − b (base 2, with borrows)
Multiply two binary numbers using the shift-and-add algorithm: for each 1 bit in the multiplier, add a shifted copy of the multiplicand.
a × b (shift-and-add)
Integer-divide two binary numbers and return both the quotient and the remainder. Uses repeated subtraction (or shift-and-subtract) the way long division does in base 10.
a ÷ b → quotient and remainder
Binary is a positional number system in base 2 — it uses only the digits 0 and 1. Every position represents a power of two, increasing from right to left: the rightmost digit is the ones place (2⁰), then twos (2¹), fours (2²), eights (2³), and so on. To convert a decimal number to binary, divide by 2 repeatedly and read the remainders from bottom to top. To convert binary to decimal, multiply each bit by its place value and add. Binary arithmetic (add, subtract, multiply, divide) follows the same column rules as base-10 arithmetic, except carries and borrows happen at 2 instead of at 10.
Convert the decimal number 42 to binary.
Therefore, 42 (decimal) = 101010 (binary).
A bit is a single binary digit, 0 or 1. Four bits make a nibble (16 possible values, 0–15, used to represent one hexadecimal digit). Eight bits make a byte, the standard unit of memory addressing — one byte can hold 256 different values (0 to 255 unsigned, or −128 to 127 signed). Larger groups have names too: 16 bits = word (on most architectures), 32 bits = double word, 64 bits = quad word. To represent negative numbers in a fixed bit width, computers use two's complement: invert every bit and add 1. Two's complement makes signed addition and subtraction use the exact same circuitry as unsigned arithmetic — a major reason it became the standard.
Divide the decimal number by 2 repeatedly, recording the remainder (0 or 1) at each step. When the quotient reaches 0, stop. Read the remainders from bottom to top — that sequence is the binary representation. For example, 42 ÷ 2 gives remainders 0, 1, 0, 1, 0, 1 from bottom to top, so 42 in binary is 101010.
Multiply each bit by its place value (a power of 2) and add the results. The rightmost bit is 2⁰ = 1, the next is 2¹ = 2, then 2² = 4, 2³ = 8, and so on. For example, 10110101 = 128 + 32 + 16 + 4 + 1 = 181.
Align the numbers by their rightmost bit and add column by column. The rules per column are 0+0 = 0, 0+1 = 1, 1+0 = 1, and 1+1 = 0 with a carry of 1 to the next column. For example, 101 + 011 = 1000 (5 + 3 = 8).
Binary is the base-2 number system. It uses only two digits, 0 and 1, instead of the ten digits of decimal. Each position in a binary number represents a power of 2, so the rightmost digit is the ones place, then twos, fours, eights, and so on doubling at each step.
Digital circuits are built from switches that are either on or off, which maps directly to the two digits of binary. Representing data with only two voltage levels (high and low) is far more reliable than trying to distinguish ten or more levels in the presence of electrical noise. Binary also makes arithmetic circuits much simpler: a binary full-adder has only a handful of logic gates.
Read the bits left to right just as you would any number, but remember that the place values increase right to left in powers of 2. The leftmost bit is the most significant (largest place value) and the rightmost bit is the least significant (the ones place). You don't pronounce each bit individually — for example, you'd say '1 0 1 0 1 0' or call it 'one-oh-one-oh-one-oh in binary' rather than reading it as 'one hundred and one thousand ten'.
A byte is 8 bits, the standard unit of memory addressing on essentially every modern computer. An 8-bit byte can hold one of 256 distinct values (0 to 255 unsigned, or −128 to 127 in two's-complement signed form). A nibble is half a byte (4 bits, 16 values, one hexadecimal digit).
In a fixed-width signed integer, computers use two's-complement encoding: to negate a value, flip every bit and add 1. With this scheme, addition and subtraction use the same circuitry for signed and unsigned values. This calculator shows negative subtraction results with a plain '-' sign prefix rather than encoding them in two's complement, because that encoding only makes sense with a chosen bit width.
Reference: Standard positional base-2 numeral system and binary arithmetic algorithms; two's complement and IEEE byte-width conventions from Patterson & Hennessy, Computer Organization and Design.
Every position in a binary number has a weight that is a power of two, increasing right to left. To convert a binary number to decimal, multiply each bit by its place value and add the results:
Where:
For example, 10110101 = 128 + 32 + 16 + 4 + 1 = 181. Every binary number expands this way, which is why an 8-bit number can represent any value from 0 to 255 (one byte).
Place-value ladder for an 8-bit example. Each column is a power of two, with weights doubling right to left. Setting bits 7, 5, 3, and 1 gives 128 + 32 + 8 + 2 = 170.
8-bit place-value ladder. Each bit is multiplied by its place weight (a power of 2) and the products are summed to give the decimal value.
Decimal to Binary
42 = 101010₂
Binary to Decimal
10110101₂ = 181
Binary Addition
101 + 011 = 1000₂