Number system converter
Type a number in any base and get it in binary, octal, decimal, hexadecimal, BCD and Gray code with the repeated division and multiplication method, its one's and two's complement forms, binary addition and subtraction with carries and flags, and its IEEE 754 floating-point encoding.
What you can do
- Base conversion with fractions.
- Sign-magnitude, one's and two's complement, excess.
- Binary arithmetic with C, V, N, Z flags.
- 32-bit IEEE 754.
Frequently asked questions
How do you get the two's complement?
Invert every bit and add 1.
Guide: number systems, two's complement and IEEE 754
Computers store everything in binary. To program at a low level, design digital circuits or understand why 0.1 + 0.2 is not exactly 0.3, you need to convert between bases, represent negative numbers and know the floating-point format. This guide explains each step with worked examples.
Bases 2, 8, 10 and 16
In base b, each digit is worth its value times a power of b depending on its position. For example, 1001 1100₂ = 128 + 16 + 8 + 4 = 156. Octal (base 8) and hexadecimal (base 16, with digits 0–9 and A–F) are compact ways to write binary: each octal digit stands for 3 bits and each hexadecimal digit for 4.
Example 1: 156 to binary, octal and hexadecimal
- Repeated division by 2: 156 → 78 remainder 0 → 39 r 0 → 19 r 1 → 9 r 1 → 4 r 1 → 2 r 0 → 1 r 0 → 0 r 1. Reading the remainders from bottom to top: 1001 1100₂.
- Hexadecimal: groups of 4 bits from the right: 1001 | 1100 = 9 | C, that is, 9C₁₆.
- Octal: groups of 3 bits: 10 | 011 | 100 = 2 | 3 | 4, that is, 234₈.
Example 2: fractions
The fractional part is multiplied by 2, taking the integer part at each step: 0.625 × 2 = 1.25 → 1; 0.25 × 2 = 0.5 → 0; 0.5 × 2 = 1.0 → 1. So 0.625 = 0.101₂ = 0.5₈ = 0.A₁₆. Some simple decimal fractions, such as 0.1, have no finite binary representation: they repeat forever, which is why computers round them.
Negative numbers with n bits
- Sign and magnitude: the first bit is the sign. −5 with 8 bits = 1000 0101.
- One's complement: invert every bit of +5: 1111 1010.
- Two's complement: one's complement plus 1: 1111 1011. It is the one almost every processor uses, because addition works the same for positive and negative numbers and there is a single zero. With n bits it covers −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1, that is, −128 to 127 with 8 bits.
- Excess-2ⁿ⁻¹: add 128 to the value: −5 + 128 = 123 = 0111 1011. It is used in the IEEE 754 exponent, with excess 127.
Example 3: overflow
100 + 50 with 8 bits in two's complement: 0110 0100 + 0011 0010 = 1001 0110. Unsigned it is 150, correct; but signed, that pattern is −106. There was overflow: two positive numbers gave a negative result, because 150 does not fit in the range −128…127. The processor detects it with the V flag, the exclusive OR of the carry into the sign bit and the carry out of it.
Example 4: 32-bit IEEE 754 floating point
A number is stored as sign (1 bit), exponent with excess 127 (8 bits) and mantissa (23 bits), with an implicit leading 1. For 0.15625:
- Positive sign: 0.
- In binary, 0.15625 = 0.00101₂ = 1.01 × 2⁻³.
- Stored exponent: −3 + 127 = 124 = 0111 1100.
- Mantissa: the bits after the 1., that is, 01 followed by zeros.
- Result: 0 01111100 0100…0 = 0x3E200000.
Every value in these examples matches what the tool shows.
How to use the tool
- In "Base conversion", type the number (it accepts negatives and fractions, such as −45, 101.011 or 3F.8), its base and the number of bits.
- Read the result in every base (also BCD and Gray code), the signed representations and the steps: repeated division, multiplication of the fraction and bit grouping.
- In "Binary arithmetic", add or subtract with n bits and look at the carries and the C, V, N and Z flags.
- In "IEEE 754", type a decimal or a 0x… pattern to see its fields.
Common mistakes
- Reading the remainders from top to bottom: the first remainder is the least significant bit.
- Grouping the bits from the left in the integer part: group from the radix point.
- Forgetting to add 1 in two's complement.
- Confusing carry with overflow: C matters in unsigned arithmetic and V in signed arithmetic.
Further reading
M. M. Mano and M. D. Ciletti, Digital Design (Pearson); D. A. Patterson and J. L. Hennessy, Computer Organization and Design (Morgan Kaufmann); the IEEE 754 standard. Simuveliq is not affiliated with these authors, publishers or IEEE.
More tools
Versión en español
About Simuveliq · Privacy policy · Contact