Subtopic Notes

1.1 - Data Representation

1. Information representation

Denary System

  • Traditional number system of base 10, Digits 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

Prefixes

Denary PrefixFactor ValueBinary PrefixFactor Value
Kilobyte - (kB)x10³Kibibyte - (KiB)x2¹⁰
Megabyte - (MB)x10⁶Mebibyte - (MiB)x2²⁰
Gigabyte - (GB)x10⁹Gibibyte - (GiB)x2³⁰
Terabyte - (TB)x10¹²Tebibyte - (TiB)x2⁴⁰
Petabyte - (PB)x10¹⁵Pebibyte - (PiB)x2⁵⁰
Exabyte - (EB)x10¹⁸Exbibyte - (EiB)x2⁶⁰

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 1000₂
  • 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: 100011₂

Binary To Denary

  • Identify the position (or power of 2) of each digit, starting from the rightmost digit (which is 2⁰) 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 1100₂ to Denary
2⁷2⁶2⁵2⁴2⁰
1286432168421
10111100

1011 1100₂ = 2⁷ + 2⁵ + 2⁴ + 2³ + 2² = 128 + 32 + 16 + 8 + 4 = 188₁₀

Binary To Hexadecimal

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

Hexadecimal To Binary

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

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
    554₁₀ = 256 * 2 + 16 * 2 + 10 = 16² * 2 + 16¹ * 2 + 10 = 2 2 A₁₆

Hexadecimal to Denary

  • Find the denary value for each digit
  • Multiply with appropriate 16’s power and add up
  • Example: E4₁₆
    • E = 14, 4 = 4
    • Answer: 14 * 16¹ + 4 * 16⁰ = 14 * 16 + 4 = 224 + 4 = 228₁₀

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
  • Empty positions are filled with 0.
  • 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)

Arithmetic Binary Shift

Moves all bits 1-place to the right and copies the sign bit into the MSB

Cyclic Shift

Bits which are removed from one end is added to the other

One’s Complement

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

  • Example: 47₁₀ = 0101111₂

    One’s Complement Representation: 101000₂

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) | 11000010
  • Convert to two’s complement (add 1) | 11000011

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

Binary Subtraction

  • 1) For number with different length, add 0 to the smaller to give same length
  • 2) Add a 0 as MSB (will represent the sign bit) to both numbers
  • 3) Convert the subtrahend to its 2’s complement
  • 4) Add with the minuend
  • 5) Omit the carry if working with signed two’s complement numbers.
  • Example: 1100 - 10001
    • 1) The question becomes 01100 -10001
    • 2) The question becomes 001100 - 010001
    • 3) 2’s complement of subtrahend = 101111
    • 4) 001100 + 101111 = 111011
    • 5) No carry so answer is 111011 which is a 2’s complement representation

Text

  • A character set generally includes upper & lower case letters, number digits, punctuation marks and other characters
  • Character sets use different binary representations for each character via character encoding
  • Value of A = 65, a = 97, 0 = 48
  • Character Encoding Standards:
ASCIIExtended ASCIIUnicode
Only English alphabets can be representedASCII’s extension - Also includes most European languages’ alphabetsSuperset for ASCII & extended ASCII - recognized by various global languages
Each character encoding takes up 7 bits, hence 128 possible charactersASCII extended to 8 bits, hence 256 possible characters.Greater range of characters, as it uses 2 or 4 bytes per character.
Takes less space2 or 4 times more space needed per character