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:| Hex | Binary | Decimal |
| 0 | 0000 | 0 |
| 5 | 0101 | 5 |
| A | 1010 | 10 |
| F | 1111 | 15 |
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:
0000 0000 0000 0001 = 1-1 = 1111 1111 1111 1111 = xFFFFTo negate a number: invert all bits, then add 1.
For example, to get -5:
0000 0000 0000 01011111 1111 1111 10101111 1111 1111 1011 = xFFFBIn 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?