Computer Codes
Computer Codes
PROGRAMMING
(Computer Codes)
ENGR. MIGUEL ALBERT D. CALIZAR, ECT
Learning Objectives
In this chapter you will learn about:
● Computer Data
● Computer codes: representation of data in binary
● Most commonly used computer codes
● Collating sequence
Data Types
● Numeric Data consists of only numbers 0, 1, 2, …, 9.
● Alphabetic Data consists of only the letters A, B, C, …, Z, in both
uppercase and lowercase, and blank character.
● Alphanumeric Data is a string of symbols where a symbol may be one of
the letters A, B, C, …, Z, in either uppercase or lowercase, or one of
the digits 0, 1, 2, …, 9, or a special character,
such as + - * / , . ( ) = etc.
Computer Codes
● Computer codes are used for internal representation of data in
computers.
● As computers use binary numbers for internal data representation,
computer codes use binary coding schemes.
● In binary coding, every symbol that appears in the data is represented
by a group of bits.
● The group of bits used to represent a symbol is called a byte.
● As most modern coding schemes use 8 bits to represent a symbol, the term
byte us often used to mean a group of 8 bits.
● Commonly used computer codes are BCD, EBCDIC, and ASCII.
BCD
● BCD stands for Binary Coded Decimal.
● It is one of the early computer codes.
● It uses 6 bits to represent a symbol.
● It can represent 64 (26) different characters.
Coding of Alphabetic and
Numeric Characters in BCD
BCD Code BCD Code
Char Octal Char Octal
Zone Digit Zone Digit
A 11 0001 61 N 10 0101 45
B 11 0010 62 O 10 0110 46
C 11 0011 63 P 10 0111 47
D 11 0100 64 Q 10 1000 50
E 11 0101 65 R 10 1001 51
F 11 0110 66 S 01 0010 22
G 11 0111 67 T 01 0011 23
H 11 1000 70 U 01 0100 24
I 11 1001 71 V 01 0101 25
J 10 0001 41 W 01 0110 26
K 10 0010 42 X 01 0111 27
L 10 0011 43 Y 01 1000 30
M 10 0100 44 Z 01 1001 31
Coding of Alphabetic and
Numeric Characters in BCD
BCD Code Octal
Character
Zone Digit Equivalent
1 00 0001 01
2 00 0010 02
3 00 0011 03
4 00 0100 04
5 00 0101 05
6 00 0110 06
7 00 0111 07
8 00 1000 10
9 00 1001 11
0 00 1010 12
BCD Coding Scheme(Example 1)
Example
Show the binary digits used to record the word BASE in BCD.
BCD Coding Scheme(Example 2)
Example
Using octal notation, show BCD coding for the word DIGIT.
EBCDIC
● EBCDIC stands for Extended Binary Coded Decimal Interchange Code.
● It uses 8 bits to represent a symbol.
● It can represent 256 (28) different characters.
Coding of Alphabetic and
Numeric Characters in BCD
Coding of Alphabetic and
Numeric Characters in BCD
Zoned Decimal Numbers
● Zoned decimal numbers are used to represent numeric values (positive,
negative, or unsigned) in EBCDIC.
● A sign indicator (C for plus, D for minus, and F for unsigned) is used
in the zone position of the rightmost digit.
● Zones for all other digits remain as F, the zone value for numeric
characters in EBCDIC.
● In zoned format, there is only one digit per byte.
Examples Zoned Decimal Numbers
● Packed decimal format requires fewer number of bytes than zoned decimal
format for representing a number
● Numbers represented in packed decimal format can be used for arithmetic
operations
Examples of Conversion of Zoned
Decimal Numbers to Packed
Decimal Format
Numeric EBCDIC Sign
Value Indicator
345 F3F4F5 F For unsigned
Using binary notation, write EBCDIC coding for the word BIT.
How many bytes are required for this representation?
ASCII
● ASCII stands for American Standard Code for Information Interchange.
● ASCII is of two types: ASCII-7 and ASCII-8
● ASCII-7 uses 7 bits to represent a symbol and can represent 128 (27)
different characters.
● ASCII-8 uses 8 bits to represent a symbol and can represent 256 (28)
different characters.
● First 128 characters in ACII-7 and ASCII-8 are same.
Coding of Numeric and
Alphabetic Characters in ASCII
Coding of Numeric and
Alphabetic Characters in ASCII
ASCII-7 Coding Scheme
Example
● Encoding Forms:
• UTF-8, UTF-16, UTF-32
Collating Sequence
● Collating sequence defines the assigned ordering among the characters
used by a computer
● Collating sequence may vary, depending on the type of computer code used
by a particular computer
● In most computers, collating sequences follow the following rules:
1. Letters are considered in alphabetic order
(A < B < C … < Z)
2. Digits are considered in numeric order
(0 < 1 < 2 … < 9)
Sorting in EBCDIC
Example