Two’s complement encoder
Encode a signed integer as a fixed-width two’s complement bit pattern. Enter your values below to see the result and method.
inputs.
Related calculators and articles
Compare methods and explore more free tools in computer science.
How to use the Two’s complement encoder
Encode a signed integer as a fixed-width two’s complement bit pattern. Use the free tool above without creating an account.
What it calculates
Encode a signed integer as a fixed-width two’s complement bit pattern. The output reflects the input definitions and conventions used by the formula, so keep formats and units consistent when comparing scenarios.
Inputs and units
Enter Signed integer and Bit width. Review the labels and example values before calculating.
- Signed integer: enter a value in the unit shown; the browser checks the accepted format and range.
- Bit width: enter a value in the unit shown; the browser checks the accepted format and range.
Formula and method
encoded value = n mod 2^b, written as b binary digits
The calculator applies this relationship directly and keeps intermediate values unrounded for the displayed estimate.
Worked example
−42 in 8-bit two’s complement is 11010110₂.
How to interpret the result
Use the result to answer the specific sizing, encoding, performance, or representation question stated on this page. It is conditional on the chosen inputs; change one input at a time to see how the estimate responds.
Assumptions and limitations
The integer must fit the signed range for the selected width. The output is a bit pattern; interpretation depends on knowing that width and signed convention.
Frequently asked questions
How is a negative value encoded?
For a b-bit word, the signed integer is represented by its residue modulo 2ᵇ, padded to b binary digits. For example, −42 in 8 bits is 11010110.
Which integer values fit in b bits?
The signed range is −2^(b−1) through 2^(b−1)−1. Inputs outside that range cannot be represented without truncation or overflow and are rejected.
Does the output include a sign character?
No. The output is exactly b binary digits; the most significant bit participates in two’s-complement interpretation rather than being a separate sign symbol.
How do I use the Two’s complement encoder?
Enter Signed integer, Bit width. Match the units shown beside each field and review the result together with the assumptions below.
What is a worked example of Two’s complement encoder?
−42 in 8-bit two’s complement is 11010110₂.
Read the calculation methodology and privacy policy.