Subtopic Notes

1.1 Number systems

1. Data representation

Denary System

  • Traditional number system of base 10, Values from 0 to 9

Binary System

  • Base 2 number system with values of 0 and 1
  • 0 represents off/false/dark spot/low voltage
  • 1 represents on/true/light spot/high voltage
  • Any form of data needs to be converted to binary to be processed by a computer
  • Data is processed using logic gates and stored in registers
  • Each digit is called Bit (Bit = Binary Digit)
  • Most left bit is called the MSB (Most Significant Bit)
  • The right most bit is called the LSB (Least Significant Bit)
  • 4 bits = a nibble
  • 8 bits = a byte

Hexadecimal Number System

  • Base 16 number system
  • Values from 0 to 9 followed by A to F
  • Advantages:
    • Easier to code, faster, and less error-prone than binary
  • Applications: IP Address, Error Codes, URL, Assembly Language, Memory Dumps, Locations in Memory, Color Codes of HTML, MAC Address

Number Values

BinaryHexDenaryBinaryHexDenary
000000100088
000111100199
0010221010A10
0011331011B11
0100441100C12
0101551101D13
0110661110E14
0111771111F15

Binary Coded Decimals (BCD)

  • Each positive denary digit is represented using a nibble (4 bits)
  • Example: Convert 928 to binary
    • 9 = 1001 | 2 = 0010 | 8 = 1000
    • Binary Value: 1001 0010 10002
  • Applications
    • Displaying numbers in electronic device (eg. Calculators)
    • Accurately measuring decimal fractions
    • Electronically coding denary numbers

Converting Number Systems (Examples)

Denary to Binary

Method 1

Break the decimal number down into a sum of powers of 2 and then write the binary value
Example: Representing 553 in binary
553 = 512 + 32 + 8 + 1
Binary: 0010 0010 1001

5122561286432168421
1000101001

Method 2

NumberNumber / 2Remainder
35171
1781
840
420
210
101
  • Successively divide the denary value by 2, noting every remainder
  • Repeat until quotient is 0
  • Write the remainders in reverse order
  • Example: Convert 35 to Binary
    Refer to the table to the right
    Answer: 1000112

Binary To Denary

  • Identify the position (or power of 2) of each digit, starting from the rightmost digit (which is 20) and moving to the left.
  • Multiply each binary digit by its corresponding power of 2.
  • Sum all the products to get the denary equivalent.
  • Example: 1011 11002 to Denary
2726252423222120
1286432168421
10111100

1011 11002 = 27 + 25 + 24 + 23 + 22 = 128 + 32 + 16 + 8 + 4 = 18810

Binary To Hexadecimal

  • Make groups of four bits and convert each to hexadecimal
  • Example: 1100 1110 = C E16

Hexadecimal To Binary

  • Convert each Hex digit to binary and write serially
  • Example: F B = 1111 10112

Denary to Hexadecimal

  • Method 1: Convert the value to binary, and then convert it to hex
  • Method 2: Break the decimal number down into a sum of powers of 16
    Example: 554 to Hexadecimal
    55410 = 256 * 2 + 16 * 2 + 10 = 162 * 2 + 161 * 2 + 10 = 2 2 A16

Hexadecimal to Denary

  • Find the denary value for each digit
  • Multiply with appropriate 16’s power and add up
  • Example: E416
    • E = 14, 4 = 4
    • Answer: 14 * 161 + 4 * 160 = 14 * 16 + 4 = 224 + 4 = 22810

Binary Operations

Adding two positive 8-bit binary

Normal Binary Addition

0 + 0 = 01 + 0 / 0 + 1 = 11 + 1 = 0 (1 carry)1 + 1 + 1 = 1 (1 carry)

Overflow

  • A computer or a device has a predefined limit that it can represent or store, for example 16-bit
  • When adding two values, an overflow error occurs when a value outside this limit should be returned
  • E.g. The solution has 9 bits (Value greater than 255), but the question has 8 bits per value (8-bit register), the 9th bit (most left bit) is called overflow.
  • Shows that memory doesn’t have enough space to store the answer

Example of Addition

Add: 1011 0111 and 0111 1111

Carry1111111
Byte 110110111
Byte 201111111
Solution(Overflow): 100110110

Note: When adding values, move from RHS to LHS using above rules. For overflow bit denote using bracket
Answer: (1) 0011 0110

Logical Shifts

  • Moving a binary value to the left or the right
  • Most significant bits (MSB) or the least significant bits (LSB) are lost
  • Shifting 1100 1010 two places to the left = 0010 1000
  • Shifting 1100 1010 two places to the right = 0011 0010
  • Each left shift multiplies the original number by 2 (Data may be lost)
  • Each right shift divides the original number by 2 (Data may be lost)

One’s Complement

  • The negative version of a binary number is formed by flipping all the bits

  • Example: 4710 = 01011112

    One’s Complement Representation: 1010002

Two’s Complement

  • Used to represent signed integer
  • The most significant bit (MBS) becomes a sign bit denoting positive or negative number
  • Maximum positive number in 8 bits: 127
  • Maximum negative number in 8 bits: -128

Converting negative denary to two’s complement (Example: –61):

  • Find the binary equivalent of the denary number (ignoring the negative sign) | 61 = 111101
  • Add extra 0 bits before the MSB | 00111101
  • Convert to one’s complement (flip the bits) | 11010101
  • Convert to two’s complement (add 1) | 11010110

Converting binary two’s complement into denary (example 11010110):

  • Flip all the bits | 00101001
  • Add 1 | 00101010
  • Convert to denary and put a negative sign | -42