Subtopic Notes
1.1 Data Representation
1. Information 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
| Binary | Hex | Denary | Binary | Hex | Denary |
|---|---|---|---|---|---|
| 0000 | 0 | 0 | 1000 | 8 | 8 |
| 0001 | 1 | 1 | 1001 | 9 | 9 |
| 0010 | 2 | 2 | 1010 | A | 10 |
| 0011 | 3 | 3 | 1011 | B | 11 |
| 0100 | 4 | 4 | 1100 | C | 12 |
| 0101 | 5 | 5 | 1101 | D | 13 |
| 0110 | 6 | 6 | 1110 | E | 14 |
| 0111 | 7 | 7 | 1111 | F | 15 |
Prefixes
| Denary Prefix | Factor Value | Binary Prefix | Factor Value |
|---|---|---|---|
| Kilobyte - (kB) | x103 | Kibibyte - (KiB) | x210 |
| Megabyte - (MB) | x106 | Mebibyte - (MiB) | x220 |
| Gigabyte - (GB) | x109 | Gibibyte - (GiB) | x230 |
| Terabyte - (TB) | x1012 | Tebibyte - (TiB) | x240 |
| Petabyte - (PB) | x1015 | Pebibyte - (PiB) | x250 |
| Exabyte - (EB) | x1018 | Exbibyte - (EiB) | x260 |
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
| 512 | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 1 |
Method 2
| Number | Number / 2 | Remainder |
|---|---|---|
| 35 | 17 | 1 |
| 17 | 8 | 1 |
| 8 | 4 | 0 |
| 4 | 2 | 0 |
| 2 | 1 | 0 |
| 1 | 0 | 1 |
- 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
| 27 | 26 | 25 | 24 | 23 | 22 | 21 | 20 |
|---|---|---|---|---|---|---|---|
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
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 to
- 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 = 0 | 1 + 0 / 0 + 1 = 1 | 1 + 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.
- Indicates that memory doesn’t have enough space to store the answer
Example of Addition
Add: 1011 0111 and 0111 1111
| Carry | 1 | 1 | 1 | 1 | 1 | 1 | 1 | ||
|---|---|---|---|---|---|---|---|---|---|
| Byte 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | |
| Byte 2 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
| Solution | (Overflow): 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
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)
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: 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
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:
| ASCII | Extended ASCII | Unicode |
|---|---|---|
| Only English alphabets can be represented | ASCII’s extension - Also includes most European languages’ alphabets | Superset for ASCII & extended ASCII - recognized by various global languages |
| Each character encoding takes up 7 bits, hence 128 possible characters | ASCII extended to 8 bits, hence 256 possible characters. | Greater range of characters, as it uses 2 or 4 bytes per character. |
| Takes less space | 2 or 4 times more space needed per character |
