Number Systems

Denary (0 - 9) (the one we use most commonly) (10)
Binary (0 and 1) (the only one used to store data) (2)
Hexadecimal (0 - 9, A-F) (16)
Binary Conversions:
Bit – a 0 or a 1 (smallest unit of data a computer can use)
4 bits – nibble
8 bits – a byte
1000 bits – 1 Kilobyte (KB)
1000 KB – 1 Megabyte (MB)
1000 GB – 1 Gigabyte (GB)
1000 GB – 1 Terabyte (TB)

1024 bits – 1 Kibibyte (1KiB)
1024 KiB – 1 Mebibyte (MiB)
1024 MiB – 1 Gibibyte (GiB)
1024 GiB – 1 Tebibyte (TiB)
n-bits – 2^n possible combinations

Binary Addition

Binary Addition rules:
0 + 0 = 0
0 + 1 = 1
1 + 1 = 0 Carry 1
1 + 1 + 1 = 1 Carry 1
an overflow – when there are not enough bits to store the data (note: the computer does not give an error message)

Signed Binaries

Signed binaries are often used to represent negative numbers in binary. The leftmost bit is called the Most Significant Bit (MSB) and determines the sign, with 0 being positive and 1 being negative.

Sign & Magnitude

the leftmost bit represents the sign

  • 0 is +
  • 1 is -

Example:
1011 = -3
0101 = 5

Two's Complement

the leftmost bit is sign and magnitude
Example:
1001 = -7
To find the negative number in binary (Two's compliment)
Find binary for positive number
Flip (0 -> 1, 1 ->0)
Add 1

Range of combinations possible in binary:
N-bit = -(2n-1) to 2

Binary Shifts

Left Shift Right Shift
Logical Shift Multiply unsigned binary numbers by powers of 2 Divide unsigned binary by powers of 2
Arithmetic Shift Multiply signed binary numbers by powers of 2 Divide signed binary by powers of 2

Logical left shift

Used to multiply unsigned binary numbers by powers of 2
Example:

  • Multiply 0101 by 2 (2^1)
  • Shift number one place to left
  • Put one zero in the space
  • Answer: 01010

Check

  • 0101 = 4 + 1 = 5
  • 5 * 2 = 10
  • 01010 = 8 + 2 = 10

Logical right shift

Used to divide unsigned binary by powers of 2
Example

  • Divide 1100 by 2 (2^1)
  • Shift number one place to right
  • Put one zero in the space
  • Unless asked for 4 digit format
  • Ignore digits beyond the binary line
  • Answer = 0110

Check

  • 1100 = 8 + 4 = 12
  • 12 ÷ 2 = 6
  • 0110 = 4+2 = 6

Arithmetic left shift

Used to multiply signed binary by powers of 2
Same as logical left shift.

Arithmetic right shift

Used to divide signed binary by powers of 2
In signed binary, logical shifts may cause the sign to change. An arithmetic shift stops this
The MSB (Most significant bit) is copied as well as shifted right. The effect is to divide by 2
Example

  • Divide 1100 by 2 (21)
  • Shift number one place to right
  • Copy first digit
  • Ignore digits beyond the binary line
  • Answer = 1110

Check:

  • 1110
  • Flip: 0001
  • Plus 1: 0010
  • Ans = -1
  • 1100
  • Flip: 0011
  • Plus 1: 0100
  • Ans = -4
  • -4 / 2 = -2