Foundations

Number Systems

Binary, hexadecimal, and two's complement representation.

Binary and Hexadecimal

Computers operate in binary (base 2). Each digit is a 0 or 1, called a bit. In LC-3, everything is 16 bits wide.

Hexadecimal (base 16) is a convenient shorthand — each hex digit represents exactly 4 bits:
HexBinaryDecimal
000000
501015
A101010
F111115
So x3000 = 0011 0000 0000 0000 in binary = 12288 in decimal.

Two's Complement

LC-3 uses two's complement to represent signed integers. In a 16-bit system:

  • Positive numbers: 0000 0000 0000 0001 = 1
  • Negative numbers: flip all bits and add 1
  • -1 = 1111 1111 1111 1111 = xFFFF
  • Range: -32768 to 32767
  • To negate a number: invert all bits, then add 1.

    For example, to get -5:

  • 5 = 0000 0000 0000 0101

  • Invert: 1111 1111 1111 1010

  • Add 1: 1111 1111 1111 1011 = xFFFB
  • In LC-3 assembly, prefix numbers with # for decimal (#-5), x for hex (xFF), or b for binary (b1010).

    Quiz

    What is the 16-bit two's complement representation of -1?

    Quiz

    What decimal value does x800F represent in 16-bit two's complement?