0% found this document useful (0 votes)
44 views

Chapter 4 Intro

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Chapter 4 Intro

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Chapter Four

Data Representation in Computers


4.1 Units of Data
Representation
the units are called bit, byte, and word; these
units are based on the binary number system.
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;
In the computer “ON” is represented by the
existence of current and “OFF” is represented
by the non-existence of current.
BYTE:
Bits can be organized into large units to make
them represent more and meaningful information.
The commonly used 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 byte is then used as a unit of measurement in
the computer memory, processing unit, external
storage and during communication.
Example:
 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 or 230 kilobytes or 220
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, four or eight
bytes based on the capacity of the computer.
Word length is usually given in bits.
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.
4.2Concept of Number Systems
and Binary Arithmetic
4.2.1 The Decimal Number System
is used a base ten number system.
is based on the ten different digits or symbols
(0,1,2,3,4,5,6,7,8,9).
The power starts at Zero for the position just to
the left of the decimal point.
The power incremented for each positions that
continues to the left.
For example:
 (8762)10 = (8*103) + (7*102) + (6*101) +
(2*100)
 (0.475)10= (4*10-1) + (7*10-2) + (5*10-3)
4.2.2 The Binary number system
is based on the two different digits; 0 and 1.
it is very easier for the hardware to represent the data.
is base two number system.
For example: (01100)2, (10110.011)2 , etc.

4.2.3 Octal number system


The octal number system with its eight symbols (0, 1,
2, 3, 4, 5, 6, and 7) is a base 8 system.
For example: (322)8, (10.25)8, etc.
4.2.4 Hexadecimal number system
is another number system that works exactly like the
decimal and binary number systems, except that the
base is 16.
It uses 16 symbols (0-9, and A-F characters to
represent 10-15).
For example: (8F0)16, (D.45)16, etc.
4.2.5Conversion between Number
Systems
Decimal to Binary
It is important to note that every decimal
number system has its equivalent binary
number.
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. Decimal
Binary And concatenate
Binary (collect)Decimal
the
0 0 101
remainders starting from the last up to the5 first.
01 1 110 6
10
For example:
2 111 7
11 3 1000 8
100 4 1001 9 etc
Example: Determine the binary equivalent of (44)10

2 44 Remainder

2 22 0 LSB (List Significant Bit)

2 11 0

2 5 1

2 2 1
0
2 1
1
1
MSB (Most Significant Bit)
Taking the remainder in reverse order we have 101100. Thus the binary equivalent of
(44)10 is (101100)2
 Binary to Decimal
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.
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-

1m +Xn*m
1 0

=Y10

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
 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.
Examples

Example 1: Convert 1001001 to octal


1001001= 001,001,001
= (111)8
Example 2: Convert 101101001 to octal
101101001 =101,101,001
=(551)8
Example 3: Convert 10001100101010 to octal
10001100101010 = 010,001,100,101,010
= (21452)8
To convert from Octal to binary, convert each
octal digit to its equivalent 3 bit binary starting
from right.

Example1: Convert (675) eight to binary


675eight =110 111 101
=(110111101)two
Example 2: Convert 231eight to binary
231eight = 010 011 001
=(10011001)two
Example 3: Convert 21452 eight to binary
21452 eight = 010,001,100,101,010
= (10001100101010)two
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.
Example1: Convert 111100100 to hexadecimal
111100100 =0001 1110
0100
=1 14 4
=1 E 4
= (1E4)16

Example2: Convert 111001111 to Hexadecimal


111001111 =0001 1100 1111
=1 12 15
=1 B F
=(1BF)16
To convert from Hexadecimal to binary convert
each hex. Digit to its equivalent 4-bit binary
starting from right.

Example 1: Convert 23416 to binary


23416 =0010 0011 0100
= (1000110100)2

Example 2: Convert 2AC16 to binary


2AC16 =0010 1010 1100
=(1010101100)2
Octal to hexadecimal and Vise versa
To convert from Octal to hexadecimal, first we have to convert
to binary and the binary to hexadecimal. To convert from
hexadecimal to Octal, first we have to convert to binary and
then the binary to Octal.

Example 1: Convert 2358 to hexadecimal


2358=010 011 101
=0000 1001 1101
=0 9 13
=0 9 D
=9D16
Example 2: Convert (1A)16 to Octal
1A=0001 1010
=000 011 010
= 0 3 2
=328
Converting Decimal Number with Fractions to
Binary
First change the integer part to its equivalent binary.
Multiply the fractional part by 2 and take out the integer
value, and again multiply the fractional part of the result
by 2 and take out the integer part, continue this until the
product is 0.
Collect the integer values from top to bottom &
concatenate with the integer part.
Example. A) Convert 12.2510 to binary
(12)10= (1100)2
To convert 0.25 we will multiply by 2 until the product
becomes 0. so 0.25 x 2 = 0.50
0.50 x 2 = 1.00 so the answer is 1100.01

B) Convert3.1875 to binary 11.0011


 Converting Binary with Fraction to Decimal
To convert a binary number Y1Y2Y3Y4Yn.d1d2d3…dm to decimal
first convert the integer part to decimal by using
y1 y2 y3 y4…yn=y1*2n-1+y2*2n-2+….yj*2n-j+….+yn-1*21+yn*20=Q
and
Convert the fractional part to decimal by using
d1d2d3…dm=d1*2-1+d2*2-2+d3*2-3+…+dj*2-j+..+dm*2-m=R
Then decimal equivalence of y1 y2 y3 y4…..yn.d1d2…dm will be
Q+R where Q is the integer part and R is the fractional part.
Ex1 : Convert 11001.0101 to decimal
11001 = 1x24 + 1x23 +0x22+0x21+1x20= 16+8+1=
25= Q
.0101 =0x2-1+1x2-2+0x2-3+1x2-4
= 0+¼+0+1/16
= 0+ 0.25+ 0+ 0.0625= 0.3125 = R
= 11001.0101 = 25.3125.
Ex 2: Convert 1000.1 to decimal
Conversion from Binary with Fraction to
Octal/Hexadecimal
Group three/four digits together starting from the
last digit of the integer part, and if there is less
number of digits add some zeros in the beginning.
Group three/ four digits together starting from the
first digit of the fractional part, and if there is less
number of digits add some zeros to the end.
Covert each group of the integer and the fractional
part to their equivalent Octal/hexadecimal and
collect the results by adding point (.) to separate
the integer part from the fractional part.
Exersices

Ex 1:- Covert 1010.01112 to octal


Ex2:- Covert 1110101.101112 to hexadecimal
Conversion from Octal or Hexadecimal with
Fraction to Binary
Convert each Octal/hexadecimal digit to its equivalent 3/4-
bit binary digit.
Collect the binary sequences by separating the integer part
binaries from the fractional part binaries with point (.)
Conversion from Octal with Fraction to
Hexadecimal
To convert from Octal to hexadecimal, first convert the
Octal to binary and then the binary to hexadecimal
Conversion from Hexadecimal with Fraction to
Octal
To convert from hexadecimal to Octal, first convert the
hexadecimal to binary and then the binary to Octal.
Conversion from Octal/Hexadecimal with Fraction
to Decimal.
To convert from Octal/hexadecimal to decimal, first convert
to binary and –then the binary to decimal.
4.2.6 Binary Arithmetic
ADDITION
0+0 = 0
0+1 = 1
1+0 = 1
1+1 = 10 (carry:1)
Example:
1 1 1 1 1 (carried digits)
01101
+10111
-------------
=100100
SUBTRACTION works in much the same way:
0−0=0
0 − 1 = 1 (with borrow)
1−0=1
1−1=0
One binary numeral can be subtracted from
another as follows:
* * * (starred columns are borrowed
from)
100101
− 1011
----------------
=011010
MULTIPLICATION in binary is similar to its
decimal counterpart.
For example, the binary numbers 1011 and 1010
are multiplied as follows: A x B
1 0 1 1 (A)
× 1 0 1 0 (B)
---------
0 0 0 0 ← Corresponds to a zero
in B
+ 1011 ← Corresponds to a one
in B
+ 0000
+1011
-------------------
=1101110
DIVISION is again similar to its decimal
counterpart:
101
101 |11011
−101
001
111
101
010
4.3 CODING METHODS
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 8bits to represent each
character.
It accommodates to code 28 or 256 different
characters.
This provides a unique code for each decimal
value 0 to 9 , each upper and lower case English
letter (for total of 52), and for a variety of special
Coding Examples

Character zone (4 Bit) digit (4 Bit)


0-9 15 0-9
a-i 8 1-9
j-r 9 1-9
s-z 10 2-9
A-I 12 1-9
J-R 13 1-9
S-Z 14 2-9
Character Zone Digit
a 1000 0001
b 1000 0010
A 1100 0001
B 1100 0010
0 1111 0000
9 1111 1001
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
4 bits BCD numbers are useful whenever decimal
information is transferred into or out of a digital
system.
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 for 0 and 1001 for 9.
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
Some Coding Examples
Character zone (2 Bit)
digit(4 Bit)
0-9 0 0-9
A-I 3 1-9

Character Zone
digits
A 11 0001
Q 10 1000
8 00 1000
9 00
1001
 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
Coding examples:

Charter zone (3 bit) digit (4 bit)


0-9 3 0-9
A-O 4 1-15
P-Z 5 1-10
Charter zone digit
A 100 0001
B 100 0010
P 101 0001
1 011 0001
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.
 Coding Examples:

Character zone (3 BIT) digit (4 BIT)


0-9 3 0-9
A-O 4 1-15
P-Z 5 0-10
a-o 6 1-15
p-z 7 0-10

a 0110 0001
b 0110 0010
A 0100 0001
B 0100 0010
? 0011 1111
+ 0010 1011
1 0011 0001
Unicode
has started to replace ASCII and other coding
methods at all levels.
Unicode provides a unique number for every
character, no matter what the platform, no matter
what the program, no matter what the language.
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 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).
4.4Representation of Negative
Numbers and Arithmetic
There are different ways of representing negative
numbers in a computer.
1. Sign- magnitude representation.
In signed binary representation, the left-most bit is used to
indicate the sign of the number. Traditionally, 0 is used
to denote a positive number and 1 is used to denote a
negative number. But the magnitude part will be the same
for the negative and positive values.
In general for n-bit sign magnitude representation the
range of values that can be represented are –(2 n-1-1 ) to
(2 n-1-1).
Example 2: Represent –24 using 8-bits sign
magnitude representation
24=00011000
-24 = 10011000
2. One’s Complement
 In one’s complement representation, all positive integers are
represented in their correct binary format.
 Each 0 is transformed into a 1 and each 1 into a 0.
 Example: +2 is 00000010
-2 is 11111101
 Note that in this representation positive numbers start with a 0
on the left, and negative numbers start with a 1 on the left most
bit.
Example 1: add –3 and 3 with word size 4
3 = 0011
-3 = 1100
sum = 1111 (=0)
Ex2. Add -4 and +6
- 4 is 11111011
+ 6 is 00000110
The sum is (1) 00000001
Where 1 indicates a carry. The correct result should be 2 or
00000010.
3. Two’s Complement Representation
In two’s complement representation, positive
numbers are represented, as usual, in singed
binary, just like in one’s complement.
The difference lies in the representation of
negative numbers.
A negative number represented in two’s
complement is obtained by first computing the
one’s complement and then add one.
Example: +3 is represented in signed binary as
00000011
Its one’s complement representation is
11111100.
The two’s complement is obtained by adding
one.

You might also like