Tools
Number System Converter
Type a number in any base and see it in the other three, with fractions. Below it you get the signed forms at 4, 8, 16 and 32 bits and the IEEE 754 bits of the same number. Turn on Show steps to watch the working that you would write on paper.
The tool
How it works
Converting between bases
A whole number from decimal to another base is converted by dividing by the base again and again. Each remainder is one digit, and you read the remainders from the last to the first. A fraction is converted the other way round: multiply it by the base, take the whole part as the next digit, and repeat with what is left.
From another base to decimal you add up each digit times its place value, such as 2 to the power 3, 2 to the power 2 and so on. The page does all of these with exact whole-number arithmetic, so a number is never rounded by accident.
Some fractions never end. 0.1 in decimal is 0.0001100110011... in binary, with the block 0011 repeating forever. The page writes the repeating block in brackets, as in 0.0(0011), and shows an ellipsis when it stops at 24 digits.
Negative whole numbers
Sign-magnitude keeps the size of the number and puts the sign in the leftmost bit. 1's complement flips every bit of the positive number. 2's complement flips every bit and then adds 1. Computers use 2's complement because adding two numbers works the same way whether they are positive or negative, and it has only one zero.
With n bits, 2's complement holds -2^(n-1) up to 2^(n-1)-1, so 8 bits hold -128 to 127. Sign-magnitude and 1's complement lose one value because they have both +0 and -0, so 8 bits hold -127 to 127.
IEEE 754 floating point
A float is stored as three fields: a sign bit, an exponent and a mantissa. Single precision uses 1, 8 and 23 bits with a bias of 127. Double precision uses 1, 11 and 52 bits with a bias of 1023. For a normal number the value is (-1)^sign x 1.mantissa x 2^(exponent - bias), and the leading 1 is not stored.
An exponent of all zeros means zero or a subnormal number, and an exponent of all ones means infinity or NaN. The page shows the number that is really stored, written out in full, so you can see why 0.1 becomes 0.1000000014901161... in single precision.
Questions
How do I convert decimal to binary by hand?
Divide the number by 2, write down the remainder, and divide the quotient again until it reaches 0. Read the remainders from the last one to the first. For 13: 13 / 2 = 6 r 1, 6 / 2 = 3 r 0, 3 / 2 = 1 r 1, 1 / 2 = 0 r 1, so 13 is 1101. Turn on Show steps to see this worked out for your own number.
Why does 0.1 not convert to a clean binary number?
A fraction ends in binary only if its denominator is a power of 2. 0.1 is 1/10, and 10 has a factor of 5, so the binary digits repeat forever: 0.0001100110011... A computer must cut that off, which is why 0.1 + 0.2 is not exactly 0.3 in most languages.
What is the difference between 1's complement and 2's complement?
To negate a number, 1's complement flips every bit. 2's complement flips every bit and adds 1. That small change gives 2's complement a single zero and makes subtraction a plain addition, so almost every processor uses it.
How is a decimal number stored in IEEE 754?
The number is written in binary, shifted until one 1 stands before the point, and split into three parts: the sign, the shift amount plus a bias (127 for single, 1023 for double) and the digits after the point. Show steps lists each part for your number.
Does this tool send my numbers anywhere?
No. Every conversion runs in your browser, and nothing you type is stored or sent to a server.
Learn the idea behind it
The tool is easier to use once you know what it is doing. These courses and lessons teach it from the start: the Computer Architecture course, the Digital Logic course and the Computer Networks course.
- Number systems: binary, octal and hexadecimal (Foundations)The same number written in base 10, base 2, base 8 and base 16, and how to convert between them.
- Negative numbers and overflow (Foundations)Two's complement stores negative numbers; unsigned numbers wrap around; signed overflow is a bug.
- Floating-point numbers (Foundations)Why 0.1 + 0.2 is not exactly 0.3: doubles store binary fractions with about 15 significant digits.
- Multiplication and division in hardware (Architecture)How an ALU multiplies and divides with shifts and adds: shift-and-add multiplication, Booth's algorithm for signed numbers, and restoring division.
More tools
- Ripple-carry adder simulatorThe smaller version that sits inside the lesson.
- K-Map SolverKarnaugh maps for 2 to 5 variables with SOP, POS and steps.
- Subnet CalculatorIPv4 subnets, binary AND and VLSM planning.