1
FACULTY OF COMPUTING
bit
nibbles
bytes
words
2
(LSB)
(MSB)
1 byte 2 nibbles
MSB LSB
3
Nibbles
• 4 bits
• Major uses:
• BCD (Binary Coded Decimal)
• Hexadecimal numbers
716, B16, F16
4
Bytes
• 8 bits
• Total values: 28 = 256
• Major uses:
• Numeric values (0 … 28-1 = 0 … 255)
• Signed numbers: (-128 to +127)
5
Word
• 16 bits = 2 bytes
• Bit 0 to 15
• Total values:
• 216 = 65,536
• Major uses of word:
• signed integer (-32,768 … +32,767)
• unsigned integer (0 … 216-1) = 0 … 65,535)
• UNICODE characters
6
We will learn:
• Code is unique
• Codes are easy to process
• Code is easy to represent
• Codes enable communication in place where ordinary spoken
or written language is difficult or impossible, eg Morse Code
7
Binary Coded Decimal (BCD)
1010, 1011, 1100, 1101, 1110, 1111
8
3 2 4 5
7 8 4 8
9
Gray codes
Electromechanical switches
10
Gray codes
11
Gray Code Conversion
• Binary to Gray Code
1. Record the MSB as it is
2. Add the MSB to the next bit of binary, record
the sum and neglect carry.
3. Repeat the process
12
Example:
Convert 10011010 to its equivalent gray code value
+ + + + + + +
(Maintain MSB) (Discard carries)
13
Gray Code Conversion
• Gray Code to Binary
1. Record the MSB as it is
2. Add the MSB to the next bit of Gray code,
record the sum and neglect carry.
3. Repeat the process
14
Example:
Convert the Gray code 11010111 to binary.
(Discard carries)
(Discard carries)
(Discard carries)
(Maintain MSB)
+ + + + + + +
1 0 0 1 1 0 1 0
15
Parity code
16
Examples:
1 10100111 Number Even Odd
Even Parity bit 1s Parity Parity
Even
0 1
Odd
0 10100111 1 0
Odd Parity bit
(Remember these basic rule)
17
0 1
1 0
0 1
1 0
Parity bit
Resource: [Link] 18
6 Even 0 111111 1 111111
1 Odd 1 100000 0 100000
19
20
ASCII
21
22
Resource: [Link] 23
ASCII codes – More compact table
b7 1
b6 1
b5 0
b4 b3 b2 b1
7-bits binary2
ASCII code
Examples:
B7b6b5 b4b3b2b1
110 1101
is represent as
‘m’ 1 1 0 1 m
Resource: [Link] 24
Exercise 2b.2:
25
Exercise 2b.3:
Given a string (character) UTM1435.
a) Convert the string to its ASCII hexadecimal value.
b) Calculate the odd parity bit and insert as MSB.
a) Recalculate the ASCII value in hexadecimal.
26
Character ASCII Binary Odd parity bit + New ASCII
(ASCII) (Hex) Binary (Hex)
U
T
M
1
4
3
5
h
27