ECParts Toolkit LogoECParts Toolkit

Engineering Reference

Binary, Two's Complement, Gray Code and Bitwise Reference

Lookup for fixed-width binary ranges, two's complement, masks, shifts, carry and overflow, Gray code, Boolean expressions, minterms, and Karnaugh-map terminology.

Reading Time
13 min
Format
Representation lookup
Updated
September 29, 2026

Fixed-Width Representation

Fixed-width binary representation lookup
RepresentationRange or formulaMeaningBoundary
Unsigned n-bit0 to 2ⁿ - 1All bits contribute non-negative powers of twoDo not interpret the MSB as a sign bit
Two's complement n-bit-2ⁿ⁻¹ to 2ⁿ⁻¹ - 1MSB has negative weight in signed interpretationOne more negative value than positive values
Sign extensionReplicate signed MSBPreserves a two's-complement value at greater widthOnly valid when the source is intentionally signed
Zero extensionInsert leading zerosPreserves an unsigned value at greater widthCan change a negative signed interpretation
Fixed-width wrapResult modulo 2ⁿKeeps the low n bitsWrapped bit pattern does not mean no overflow occurred
Gray codeG = B XOR (B >> 1)Adjacent sequence positions differ by one bitNot ordinary binary magnitude and not an error-correcting code

Common Bit-Width Ranges

Common fixed-width integer ranges
WidthUnsignedTwo's-complement signedHex mask
4 bit0 to 15-8 to 70xF
8 bit0 to 255-128 to 1270xFF
16 bit0 to 65,535-32,768 to 32,7670xFFFF
32 bit0 to 4,294,967,295-2,147,483,648 to 2,147,483,6470xFFFFFFFF

Bitwise Operations and Masks

Bitwise operation lookup
OperationNotationEffectTypical use
ANDA & B1 only where both bits are 1Masking selected fields
ORA | B1 where either bit is 1Setting selected bits
XORA ^ B1 where bits differToggling and change detection
NOT~A within n bitsInverts every bit in the selected widthMust mask unbounded integer representations
Left shiftA << kMoves bits toward higher positionsFixed-width high bits are discarded
Logical right shiftA >>> kShifts in zerosTreats the bit pattern as unsigned
Arithmetic right shiftA >> kReplicates the sign bitLanguage behavior and signed width must be explicit
Single-bit mask1 << positionSelects one zero-based bitPosition must be below bit width
Field mask((1 << width) - 1) << startSelects a contiguous fieldAvoid shifts at or beyond implementation width

Canonical Calculation Anchors

Binary representation calculation anchors
CaseResultInterpretation
8-bit range0 to 255 unsigned; -128 to 127 signedSame width, different interpretation
-42 in 8-bit two's complement11010110Pattern decodes to -42
Binary 1010 to Gray1111Round-trip returns 1010
Mask bits 0, 2 and 50b00100101Zero-based LSB positions
0xAC AND 0x0F0xCKeeps the low nibble
8-bit NOT 0x0F0xF0Width mask limits inversion
Logical right 0x80 by 10x40Shifts in zero
Arithmetic right 0x80 by 10xC0Replicates signed MSB

Boolean and Karnaugh-Map Terms

Boolean and Karnaugh map terminology
TermMeaningBoundary
Truth tableEnumerates function output for every input combinationn inputs produce 2ⁿ rows
MintermOne asserted input combination in canonical SOP formVariable order defines its numeric index
Don't-careInput combination permitted to be 0 or 1 during simplificationUse only when the system truly does not constrain the output
Prime implicantValid power-of-two group not contained in a larger valid groupWraparound adjacency is allowed
Essential prime implicantCovers at least one minterm no other prime implicant coversMay not complete the entire cover
Gray orderingAdjacent K-map cells differ by one variableDo not order columns as ordinary binary count

The project parser confirms A + A·B and A are not equivalent. Its K-map solver reduces minterms 1, 3, 5 and 7 for three variables to C.

Common Errors

  • Ignoring bit width.
  • Treating a bit pattern as signed and unsigned simultaneously.
  • Confusing carry with signed overflow.
  • Negating the most-negative value without widening.
  • Using zero extension for a negative signed value.
  • Applying unbounded NOT without a width mask.
  • Confusing arithmetic and logical right shift.
  • Using one-based bit positions where the implementation is zero-based.
  • Reading Gray code as ordinary binary magnitude.
  • Claiming Gray code corrects errors.
  • Ordering K-map cells in ordinary binary order.
  • Using don't-cares that are reachable system states.

Support reference

FAQ

What range fits in an unsigned n-bit value?

The range is 0 through 2^n - 1. For eight bits that is 0 through 255.

What range fits in an n-bit two's-complement value?

The range is -2^(n-1) through 2^(n-1) - 1. For eight bits that is -128 through 127.

How do I negate a two's-complement value?

Within a fixed width, invert every bit and add one. The most-negative value is a special case because its positive counterpart does not fit at the same width.

Are carry and signed overflow the same?

No. Carry-out is primarily useful for unsigned arithmetic. Signed overflow occurs when the mathematical signed result does not fit the selected two's-complement range.

What is the difference between logical and arithmetic right shift?

Logical right shift inserts zeros. Arithmetic right shift replicates the sign bit of a fixed-width signed value.

Why must bitwise NOT use a width?

Without a width, integer representations may behave as though they have unlimited leading sign bits. A width mask defines which bits are inverted.

How is Gray code calculated?

Binary-reflected Gray code is G = B XOR (B shifted right by one). Conversion back propagates XOR from the most-significant side.

Does Gray code prevent all reading errors?

No. Adjacent ideal code positions differ by one bit, which can reduce ambiguity in transitions, but synchronization, metastability and multi-step errors still require system design.

What is a minterm?

A minterm identifies one input combination for which a Boolean function is asserted, commonly indexed by the binary input pattern.

Why does a Karnaugh map use Gray-code ordering?

Gray ordering makes horizontally or vertically adjacent cells differ by one variable, enabling power-of-two grouping and variable elimination.

Is the Hex Decimal Binary Converter the same as these tools?

No. The converter changes numeral representation. Digital Logic tools additionally apply fixed width, signed interpretation, overflow, masks, shifts and logic minimization.

Connected Engineering Content

Related Calculators

Related Guides

Related References