Number Base Converter: Binary, Octal, Decimal, Hexadecimal and Two's Complement

Binary, octal, decimal and hex, with two's complement.

Calculated from standard textbook formulas, with every step shown. The formulas are fixed, so the working does not need checking: what matters is the numbers you type in. Use these calculators only if you are competent to choose the inputs (loads, material strength, dimensions, supports) and check your units and assumptions. For learning and checking your own working: design and sign-off are for a qualified engineer. Drafting Central does not store the numbers you type.

How this calculator works

Type the number and choose its base.

Choose the word size in bits.

The calculator gives the bit pattern, the hex and octal forms and the unsigned and signed values.

Formulas used

  • N = \sum d_i b^i
  • -N \equiv 2^n - N \pmod{2^n}
  • \text{range} = -2^{n-1}\ \text{to}\ 2^{n-1} - 1

Worked example

With the default numbers in the calculator above:

  1. Decimal value you typed: -5
  2. Bit pattern in 8 bits (binary): 1111 1011
  3. Hexadecimal: FB
  4. Octal: 373
  5. The pattern read as an unsigned number: 251
  6. The pattern read as a signed two's complement number: -5

Change the numbers in the calculator to see the full working, every step, for your own case.

A second worked example

A different case, with these numbers: The number (a minus sign is allowed) FF; Base of the number you typed Hexadecimal (base 16); Word size 16 bits.

  1. Decimal value you typed: 255
  2. Bit pattern in 16 bits (binary): 0000 0000 1111 1111
  3. Hexadecimal: 00FF
  4. Octal: 377
  5. The pattern read as an unsigned number: 255
  6. The pattern read as a signed two's complement number: 255

Common questions

How do I write a negative number in two's complement?

Write the positive number in binary, invert every bit and add 1. The top bit is then 1.

What is the range of an 8-bit signed number?

-128 to 127. An 8-bit unsigned number goes from 0 to 255.

Why is hexadecimal used?

One hex digit stands for exactly 4 bits, so it is a short way to write a long binary number.

Related calculators

Got a question about this? Ask an engineering question and get a plain-language answer with references.

Further reading: Any computer engineering or digital logic text (number systems, two's complement).

Need a calculator we do not have?

Tell us what you would like to calculate. We read every request and build the most asked-for ones.

We store your request (and your email if you give it) to decide what to build. We do not store the numbers you type into calculators.

Embed this calculator on your own page

Copy this code into your page. The calculator runs inside the frame and links back to Drafting Central.

Need this drawn, designed or checked?

Drafting Central is a mechanical engineering and drafting business working with customers across Australia and around the world. A calculator gives you the numbers; we can turn them into drawings and designs.

Need help with a real project?

Talk to Drafting Central →

← All engineering calculators