This two’s complement calculator converts a signed whole number into the exact binary pattern a computer would store it in, using the scheme almost every processor relies on for negative integers. Enter any whole number, positive or negative, then choose a bit width of 8, 16 or 32 bits to match the size you are working with. The calculator returns three results: the two’s complement binary pattern padded to the full width, the equivalent hexadecimal value, and the unsigned decimal value that the same bit pattern represents if read without a sign. Two’s complement works by storing negative numbers as two to the power of the bit width plus the value, which makes the leftmost bit act as a sign bit, 1 for negative and 0 for zero or positive, and lets processors add and subtract without special-case logic for negative numbers. If your number falls outside the range the chosen width can hold, for example beyond minus 128 to 127 at 8 bits, the calculator flags it as out of range rather than showing a wrong answer, so you know to pick a wider width. It suits students learning binary arithmetic, programmers debugging low-level code, and anyone checking how a negative value looks in memory. Try the built-in example of minus 5 at 8 bits to see the working before entering your own numbers.
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.
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.
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.
Minus 128 to 127. In general minus 2 to the (width minus 1) up to 2 to the (width minus 1) minus 1.
The leftmost bit. If it is 1 the number is negative, if 0 it is zero or positive.
This calculator is for students, programmers and anyone exploring number theory.
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.
Calculate.co.nz is the sister site of CalculatorHub.com, the world's largest calculator website by tool count.
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 by 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-08-07 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.