Module 2b Data Organization - Codes
Module 2b Data Organization - Codes
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
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
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)
7 8 4 8
9
Gray codes
Electromechanical switches
10
Gray codes
11
Gray Code Conversion
12
Example:
Convert 10011010 to its equivalent gray code value
+ + + + + + +
13
Gray Code Conversion
14
Example:
(Discard carries)
(Discard carries)
(Discard carries)
(Maintain MSB)
+ + + + + + +
1 0 0 1 1 0 1 0
15
Parity code
16
Examples:
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: http://en.wikipedia.org/wiki/Parity_bit 18
6 Even 0 111111 1 111111
1 Odd 1 100000 0 100000
19
20
ASCII
21
22
Resource: http://www.s4a.us/support/cimco_faq.htm 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: http://en.wikipedia.org/wiki/File:ASCII_Code_Chart-Quick_ref_card.png 24
Exercise 2b.2:
25
Exercise 2b.3:
26
Character ASCII Binary Odd parity bit + New ASCII
(ASCII) (Hex) Binary (Hex)
U
T
M
1
4
3
5
h
27