Study Web

Week 1

Bits and Number Systems

COS10004 Computer Systems · Lecture 1.4 Bits and Number Systems

INFORMATION AND COMPUTERS

  • Multiple bit representation of information:
  • numbers (32 bits) -> double/float; int
  • Characters (8 bits) -> ASCII chars
  • Numerical equivalence of multiple bits:
  • The computer doesn't know/care what the bits are supposed to be used for, it just sees bits
  • numbers/chars can be manipulated by same instructions.

ANALOGUE AND DIGITAL

  • Analogue – Data that represented on a continuous scale (real numbers)
  • e.g. voltage, height, distance, amount of magnetisation on audio tapes.
  • Good for real world measurements, transients (spikes), transistors.
  • Digital – Data that is represented as whole numbers (count)
  • e.g. class size, coins in your pocket, sound samples on CD recordings,
  • Good for noise rejection, computers.

DIGITAL ADVANTAGES

  • Digital systems are easier to:
  • design and modify
  • store data
  • maintain accuracy and precision
  • program operations
  • to protect from noise
  • to create on an IC chip
  • However the real world is mostly analogue
  • Translation is inaccurate.
  • The more bits the more precise.
  • Data in computer is stored digitally as 0s and 1s in a binary code.
  • The 1s and 0s are represented in many ways:
  • by a voltage e.g. 0 or 5 volts (actually we don’t use exact voltages) eg < 0.8 volts == 0 > 2.4 volts == 1 (TTL)
  • by the absence or presence of a pit (CD) Signal-to-noise ratio.
  • by the absence or presence of a magnetic field (disks) http:// www.linfo.org/
  • Why binary? shannon- hartley_theore
  • Simple, robust, universal laws (Shannon-Hartley), flexible m.html
  • c.f. sending decimal using voltages…. long cables… interference.)
  • groups of bits can represent numbers, characters, computer instructions.
What data can > How we interpret a 32-bit word depends on what we you represent expect! (Exercise) in 4 bytes? Float: Int: Pointer: C-string: #NaN 2686726 0x28FF2A Hello
  • Hardware has to be able to manipulate groups of bits differently depending on what they represent.
  • Amazingly, we can use combinations of Gates to do this.

8-Bit Example

Weight1286432168421
BitBit7Bit6Bit5Bit4Bit3Bit2Bit1Bit0
Value10101011
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
1 0 1 0 1 0 1 1
  • Possible interpretations:
  • Character ‘1/2’ assuming extended ASCII/ISO
  • The number -85
Bit7 Bit6 Bit5 Bit4 Bit3 Bit2 Bit1 Bit0
1 1 0 0 0 0 0 1

NUMBER SYSTEMS

  • We use a “positional number system” #big-endian
  • in decimal numbers, the further left a digit is, the greater the power of 10 it is multiplied by.
  • e,g, 348 = 3 x 102 + 4 x 101 + 8 x 100
  • This system applied to other Radix (or Bases)
  • eg. Decimal radix = 10 digits 0..9
  • Binary radix = 2 digits 0..1
  • Octal radix = 8 digits 0..7
  • Hexadecimal radix = 16 digits 0..F

BINARY NUMBERS

  • Computers work in binary numbers (2 values) e,g, binary number 010011102 is =0 * 27 + 1 * 26 + 0 * 25+ 0 * 24 + 1 * 23+ 1 * 22+ 1 * 21+ 0 * 20 =0 * 128 + 1 * 64+ 0 * 32+ 0 * 16+ 1 * 8 + 1 * 4 + 1 * 2 + 0 * 1 = 1 * 64+ 1 * 8 + 1 * 4 + 1 * 2 = 78
  • Exercise:- convert to decimal
  • 011102 = 0*24 + 1*23 + 1*22 + 1*21 + 0*20 = 8 + 4 + 2 = 14
  • 100112 = 1*24 + 0*23 + 0*22 + 1*21 + 1*20 = 16 + 2 + 1 = 19
  • notation: in maths use 011102 to indicate a binary number
  • some systems use other ways such as %01110 or b01110

Binary Counting

DecimalBinaryDecimalBinary
00000111011
10001121100
20010131101
30011141110
40100151111
501011610000
601101710001
701113111111
8100032100000
91001651000001
101010
  • Hex is another abbreviation for binary numbers.
  • Each byte represented by 2 hex digits; each hex digit represents 4 bits in an 8-bit byte.
  • Hex to binary can be done one digit at a time: e.g. what is 4E16 in binary? 4 E 0100 1110 4*16 14*1 =4x161+ 14x160 = 64+14 = 7810

HEXADECIMAL NUMBERS

  • 0=0, 1=1, 2=2, 3=3, 4=4, 5=5, 6=6, 7=7, 8=8, 9=9
  • Memorise: A=10, B=11, C=12, D=13, E=14, F=15
  • mathematically use 123016 or 1230H to indicate a hexadecimal number
  • some systems use other ways such as 0x1110 or 01110h
  • Or sometimes hex is default (not decimal!)

leading 0x means hex

HEX - BINARY (4 Bits To A Hex Digit)

HexBinary
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
A1010
B1011
C1100
D1101
E1110
F1111

BIT-WISE OPERATIONS

  • Can base decisions on a single bit #button state
  • e.g. if (bit represents True) then …
  • Usually 1 means True, 0 False.
  • Unary operation: NOT
  • Complement (“invert”, “flip”) the value
  • Binary* operations: AND, NAND, OR, NOR, XOR
  • N-bit operations: e.g. 4-input AND, OR
  • All can be implemented using binary building blocks (“2-input gates”)

SUMMARY

  • Modern computers operate with digital representations of information:
  • Easier to work with but has Implications
  • Number systems and conversions to know:
  • Binary ß à decimal
  • Hex ß à Binary
  • Hex ß à Decimal
  • And the formula in general!
  • Next Lecture: Gates