Chapter Two
Data Representation in Computers
Computer Data Representation
• We enter data into a computer or review (see) output data from a
computer using the letter of alphabet, various special symbols, and
the numerals in the decimal number system.
• But since computer is an electronic device, which understands
electrical flow (signal), there is no letter, symbol or number inside the
computer.
• Computer works with binary numbers.
Units of Data Representation
• BIT:
Bits are the smallest units and can convey only two possible
states 0 or 1;
Bit stands for Binary digits;
A bit is a single element in the computer, on a disk that stands
for either “ON” indicating 1 or “OFF” indicating 0;
Units of Data Representation
• BYTE:
is the basic “unit of data representation” in a computer system.
Byte contains 8 bits.
the total amount of data that can be represented using a single byte is 28 or
256 possible combinations.
Each byte can represent a character (a letter, a number or a special symbol)
• 1 Kilobyte (1KB) is 210 or 1024 bytes
• 1 Megabyte (MB) is 220 bytes or 210 kilobytes
• 1 Gigabyte (GB) is 230 bytes or 220 kilobytes or 210 megabytes
• 1 Terabyte (TB) is 240 bytes
Units of Data Representation
• WORD:
• Word refers the number of bits that a computer process at a time or a
transmission media transmits at a time.
• A combination of bytes, then form a “word”.
• A word can contain one, two, three or four bytes based on the capacity
of the computer.
• We say that a computer is an 8-bit, a 16 bit, a 32 bit or a 64 bit
computer to indicate that the amount of data it can process at a time.
• The larger the word length a computer has the more powerful and
faster it is.
Concept of Number Systems
• A number system defines a set of values used to represent quantity.
• There are various number systems e.g. decimal, binary, octal,
hexadecimal, etc
• For a computer, everything is a number whether it may be numbers,
alphabets, punctuation marks, its own instructions, etc.
The Decimal Number System
(Base 10)
The primary number system used is a base ten number system or
decimal number system.
The Decimal number system is based on the ten different digits or
symbols (0,1,2,3,4,5,6,7,8,9).
• For example: (8762)10 = (8*103) + (7*102) + (6*101) + (2*100)
The Binary number system
(Base 2)
• Computers do not use the ten digits of the decimal system for
counting and arithmetic.
• Binary number system is based on the two different digits; 0 and 1.
• Binary number system is base two number system.
• Computer represent data based on binary number system.
• For example: (01100)2 , (10110.011)2 , etc
• Octal number system (Base 8)
The octal number system with its eight symbols (0, 1, 2, 3, 4, 5, 6,
7) is a base 8 system.
For example: (322)8, (10.25)8, etc
• Hexadecimal number system (Base 16)
It uses 16 symbols (0-9, and A-F characters to represent 10-15).
For example: (8F0)16 , (D.45)16, etc
Conversion between Number
Systems
• Computers use binary numbers for internal data representation
whereas they use decimal numbers externally.
• Therefore, there should be some conversion between number
systems
Decimal to Binary
• It is important to note that every decimal number system has its
equivalent binary number.
• For example
Decimal to Binary
• Steps:
Begin by dividing the decimal number by 2 (the base of binary
number system)
Note (store) the remainder separately as the rightmost digit of
the binary equivalent
Continually repeat the process of dividing by 2 until quotient is
zero and keep writing the remainders after each step of
division (these remainders will either be 0 or 1)
Finally, when no more division can occur, write down the
remainders in reverse order (last remainder written first)
• Example: Determine the binary equivalent of (44)10
• 44)10 is (101100)2
Decimal to Octal and hexa
• In general to convert a decimal number X to a number in base M,
• divide X by M, store the remainder,
• again divide the quotient by M, store the remainder, and
• continue until the quotient is 0.
• And concatenate (collect) the remainders starting from the last up to the first.
• Example: Convert 7810 to base eight (Octal)
7810=1168
• Example: Convert 3010 to base sixteen (hexadecimal)
3010=1E16
Binary to Decimal
• In the binary to decimal conversion, each digit of the binary number is
multiplied by its weighted position, and
• each of the weighted values is added together to get the decimal
number.
• Example: Determine the decimal equivalent of (100100)2
• 1*25 + 0*24 + 0*23 + 1*22 + 0*21 +0*20 = 32+4 =36
• Therefore, the decimal equivalent of (100100)2 is 36
From base m (2,8,1nd 16) to
decimal
• In general To convert a number X consists of digits X1 X2 X3 …Xn in base
m to decimal; simply expand the number with base m.
• That is (X1X2X3…Xn) m =X1*mn-1+X2*mn-2 +X3*mn-3+...+ Xi*mn-i+… Xn-1m1+Xn*m0
=Y10
• Example: convert (234)8 to decimal
=2*82 + 3*81 + 4*80 = 128+24+4 = 156
• Example: convert (A1B) 16 to decimal
=A*162 + 1*161 + B*160 = 2587
Binary (base2) to Octal (base 8) or hexadecimal
(base16) and vice versa
• To convert a number in binary to octal group three binary digits
together starting from the last digit (right) and
• if there are no enough digits add zeros to the front end (left) and find
the corresponding Octal of each group.
• To convert binary to hexadecimal group four binary digits together
starting from right and
• if there are no enough digits add zeros at the left.
• To convert from Octal to binary, convert each octal digit to its equivalent 3 bit binary
starting from right.
• To convert from Hexadecimal to binary convert each hex. Digit to its equivalent 4-bit
binary starting from right.
Octal to hexadecimal and Vise
versa
• To convert from Octal to hexadecimal,
• First we have to convert to binary and
• Then the binary to hexadecimal.
To convert from hexadecimal to Octal, first we have to convert to
binary and then the binary to Octal.
Summary of conversion from One base
to another base
CODING METHODS
• the binary number system is used by the computer system to
represent the data in the computer in understandable format.
• There are a lot of ways to represent, numeric, alphabetic, and special
characters in computer’s internal storage area.
• Every character can be represented by a combination of bits that is
different from any other combination.
• There are different coding systems that convert one or more
character sets into computer codes.
• Some are: EBCDIC, BCD, ASCII-7 & ASCII-8, Unicode, etc.
EBCDIC
• Pronounced as “Eb-see-dick” and stands for Extended Binary Coded
Decimal Interchange Code.
• It is an 8-bit coding scheme: (00000000 – 11111111), i.e. it uses 8 bits
to represent each character.
• It accommodates to code 28 or 256 different characters.
• Since it is an 8-bit code, each group of the eight bits makes up one
alphabetic, numeric, or special character.
• It is a standard coding scheme for the large computers.
Example
BCD (Binary Coded Decimal)
• There were two types of BCD coding techniques used before.
• The 4 bit BCD, which represent any digit of decimal number by four
bits of binary numbers.
• If you want to represent 219 using 4 bit BCD you have to say 0010
0001 1001
BCD (Binary Coded Decimal)
• 4 bits BCD numbers are useful whenever decimal information is
transferred into or out of a digital system.
• Examples of BCD systems are electronic ousters, digital voltmeter, and
digital clocks; their circuits can work with BCD numbers.
• BCD’s are easy for conversion but slower for processing than binary.
• And they have limited numbers because with BCD we can represent
only numbers 0000 to 1111.
BCD (6-bits)
• It uses 6-bits to code a Character (2 for zone bit and 4 for digit bit)
• it can represent 26 = 64 characters (10 digits, 26 capital characters and
some other special characters).
ASCII-7
• ASCII stands for American Standard Code for Information Interchange.
• ASCII-7 used widely before the introduction of ASCII-8 (the Extended
ASCII).
• It uses 7 bits to represent a character.
• With the seven bits, 27( or 128) different characters can be coded
(0000000-1111111).
• It has 3 zone and 4 digit bits positions
Example
The ASCII System
• Also referred as ASCII-8 or Extended ASCII.
• It is commonly used in the transmission of data through data
communication and is used almost exclusively to represent data
internally in microcomputers.
• ASCII uses 8-bits to represent alphanumeric characters (letters, digits
and special symbols).
• With the 8-bits, ASCII can represent 28 or 256 different characters
(00000000-11111111).
• It assigns 4 bits for the zone and the rest for the digit.
Example
ASCII table for alphabets
Unicode
• Unicode has started to replace ASCII and other coding methods at all levels.
• It enables users to handle not only practically any script and language used
on this planet;
• it also supports a comprehensive set of mathematical and technical
symbols to simplify scientific information exchange.
• Unicode provides a unique number for every character, no matter what the
platform, no matter what the program, no matter what the language.
• Unicode was originally designed to be a 16-bit code, but it was extended so
that currently code positions are expressed as integers in the hexadecimal
range 0..10FFFF (decimal 0..1 114 111).
?