Two\u2019s Complement Calculator

This two\u2019s complement calculator shows how a signed whole number is stored in a fixed number of bits, the scheme almost every computer uses for negative integers. Enter a value and choose 8, 16 or 32 bits, and the calculator returns the two\u2019s complement binary pattern, the hexadecimal form, and the unsigned value that the same bits represent. In two\u2019s complement a negative number is stored as the bit pattern for two to the power of the width, plus the number, so the most significant bit acts as a sign bit and arithmetic just works without special cases. The method, a worked example and the assumptions are set out below.

Conservation Amendment Bill
 
Hexadecimal 
Unsigned value 

The formula

For a width of w bits, a value v is stored as v if it is zero or positive, or as 2^w + v if it is negative. The pattern fits values from minus 2^(w-1) up to 2^(w-1) minus 1. The leading bit is the sign bit.

Worked example

For minus 5 in 8 bits: 2^8 + (minus 5) = 256 minus 5 = 251, which is 11111011 in binary and FB in hex. Enter -5 with 8-bit selected to confirm.

Frequently asked questions

What is two\u2019s complement?

A way to store signed integers in a fixed number of bits, where a negative number n is held as 2 to the width plus n. It makes addition and subtraction uniform.

What range fits in 8 bits?

Minus 128 to 127. In general minus 2 to the (width minus 1) up to 2 to the (width minus 1) minus 1.

What is the sign bit?

The leftmost bit. If it is 1 the number is negative, if 0 it is zero or positive.

Who this calculator is for

This calculator is for students, programmers and anyone exploring number theory.

What this calculator assumes

  • You enter a signed integer within the range of the chosen width.
  • The width is 8, 16 or 32 bits.
  • Results are shown as the stored bit pattern.

Formula and sources

Related calculators

If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.

Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.

All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.

Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.

Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.

Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.

All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.

About & trust: Why Calculate is NZ's most comprehensive · By the Numbers · How we compare · Editorial standards · How we keep data current · NZ finance glossary · Research & data · Financial literacy NZ · About · Privacy policy · Terms of use

Reviewed and maintained. Last reviewed 2026-06-21 and checked on a twice-monthly cycle against IRD, RBNZ and Stats NZ. How we keep data current.

© 2026 Calculate.co.nz. All rights reserved. Building free NZ calculators since 2011.