Number System
Number System
computers
1
Units of 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.
• So data are represented in the form of a code that
can have a corresponding electrical signal. 2
• When data is stored, processed or
communicated within the computer system,
it is packed in units.
• Arranged from the smallest to the largest,
the units are called bit, byte, and word
• These units are based on the binary number
system.
3
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;
4
• In the computer “ON” is represented by the
existence of current and “OFF” is
represented by the non-existence of current.
• On a magnetic disk, the same information is
stored by changing the polarity of
magnetized particles on the disk’s surface.
5
BYTE
• Bits can be organized into large units to
make them represent more and meaningful
information.
• This large unit is called a byte and is the
basic “unit of data representation” in a
computer system.
6
• The commonly used byte contains 8 bits.
• Since each bit has two states and there are 8 bits
in a byte, 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
character is either a letter, a number or a
special symbol such as +,-,?,*, $, etc).
7
• A byte is then used as a unit of
measurement in the computer memory,
processing unit, external storage and during
communication.
• If the computer memory is 524288 byte,
this is expressed in short by saying 512KB,
where KB stands for kilobyte.
• 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 or8
210 megabytes
Word
• Word refers the number of bits that a
computer process at a time or a transmission
media transmits at a time.
• Although bytes can store or transmit
information, the process can even be faster
if more than one byte is processed at a once.
9
• 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.
• 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.
• The larger the word length a computer has
10
the more powerful and faster it is.
Concept of Number Systems and
Binary Arithmetic
• A number system defines a set of values
used to represent quantity.
• There are various number systems
• e.g. decimal, binary, octal, hexadecimal, etc
each differs one another by the number of
symbols used in the system.
11
• Each numbering system used different
symbols to represent a given quantity.
• For a computer, everything is a number
whether it may be numbers, alphabets,
punctuation marks, its own instructions, etc.
• The number systems that are generally used
by computers are:
• decimal, binary, octal, and hexadecimal.
12
The Decimal Number System
• 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).
13
• Starting at the decimal point and moving to
the left, each position is represented by the
base (radix) value (10 for decimal) raised to
power. The power starts at Zero for the
position just to the left of the decimal point.
• For example:
• (8762)10 = (8*103) + (7*102) +(6*101) + (2*100)
• (0.475)10= (4*10-1) + (7*10-2) + (5*10-3)
14
The Binary number system
• Binary number system is based on the two
different digits; 0 and 1.
• With binary number system, it is very easier
for the hardware to represent the data.
Binary number system is base two number
system.
• For example: (01100)2 , (10110.011)2 , etc
15
Octal number system
• 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
16
Hexadecimal number system
• 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
17
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
18
Decimal to Binary
• The method that is used to convert decimal
to binary is called the remainder method.
• This method involves the following steps.
• Begin by dividing the decimal number by 2 (the
base of binary number system)
• Note the remainder separately as the rightmost
digit of the binary equivalent
19
• the remainders after each step of division (these
remainders will either be 0 or 1)
20
• Example: Determine the binary equivalent
of (44)10
23
Conversion from base M to base
10 (decimal)
• 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
24
• Example:
1. Convert (1001001)2 to decimal = 73
2. Convert (234)8 to decimal =156
3. Convert (101)8 to decimal = 65
4. Convert (A1B) 16 to decimal = 2587
5. Covert (101)16 to decimal = 257
25
Conversion from 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.
26
• Example. Convert 1001001 to octal
1001001=001,001,001
= 1118
• Convert 101101001 to octal
101101001 =101,101,001
=5518
27
• 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.
28
• EX. Convert 111100100 to hexadecimal
111100100 =0001 1110 0100
=1 14 4
=1 E 4
= 1E416
• Convert 111001111 to Hexadecimal
111001111 =0001 1100 1111
=1 12 15
=1 B F
29
= (1BF)16
• To convert from Octal to binary, convert
each octal digit to its equivalent 3 bit binary
starting from right.
• EX. Convert (675) eight to binary
675eight =110 111 101
=110111101two
30
• Convert 231eight to binary
231eight = 010 011 001
=10011001two
• To convert from Hexadecimal to binary
convert each hex. Digit to its equivalent 4-
bit binary starting from right.
•
31
• Ex. Convert 23416 to binary
23416 =0010 0011 0100
= 10001101002
• Convert 2AC to binary
2AC16 =0010 1010 1100
=10101011002
32
Conversion from 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.
33
• EX.1. Convert 2358 to hexadecimal
2388=010 011 101
=0000 1001 1101
= 0 9 13
=9D16
• Convert 1A to Octal
1A=0001 1010
=000 011 010
=0 3 2
=328 34
Summary of conversion from one
base to another base
From base To base Method
2 10 Expand binary number in powers of 2
8 10 Go from 8…….2…….10
10 8 Go from 10 … ..2……..8
16 10 Go from 16 …….2…….10
10 16 Go from 10 …….2…….16
8 16 Go from 8 …….2…….16
35
16 8 Go from 16 …….2…….8
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.
36
• Collect the integer values from top to
bottom & concatenate with the integer part.
• A) Convert 12.2510 to binary
Ans.1100.01
• B) Convert3.1875 to binary
Ans.11.0011
37
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
• Y1Y2Y3Y4…Yn=Y1*2n-1+Y2*2n-2+….Yj*2n-j +….+Yn-
1+Y *20=Q
1*2 n 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 38
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.3125 = R
• =>11001.0101 = 25.3125.
• Ex 2: Convert 1000.1 to decimal
• 1000 = 1+23 +0+0+0=8
• 1= 1x2-1=½ = 0.5
39
• 1000.1 = 8.510
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.
40
• 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.
• Ex 1:- Covert (1010.0111)2 to octal ans12.34
• Ex2:- Covert (1110101.10111)2 to hexadecimal
ans 75.B8
41
Conversion from Octal or hexadecimal
with fraction to binary
42
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
43
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.
44
Conversion from octal/hexadecimal
with fraction to decimal.
45
Binary Arithmetic
• Binary addition
• The binary addition rules may be written as
follows:
• 0+0=0
• 0+1=1
• 1+0=1
• 1+1=0 plus a carry of 1 into the next position
• 1+1+1=1 plus a carry of 1 into the next position.
46
• Example1:
• 6+7 =13
• 110+111=1101
• Example2
• 19+31+10=60
• 10011 +11111+1010=111100
• Example 3
• 3.5+2.5=6.0
• 11.10+10.10=110.00 47
• Binary Subtraction
• It operates by the same rule as decimal
subtraction. The rule is as follows;
• 0-0=0
• 1-0=1
• 1-1=0
• 10-1=1
48
Example
49
• Binary Multiplication:
• It is a very simple process that operates by the
following obvious rulers:
• Multiplying any number by 1 rules the
multiplicand unchanged
• 0x1=0
• 1x1=1
• Multiplying any number by 0 produces 0
• 0x0=0 50
• 1x0=0
• Binary division
• The process for dividing one binary number
(the dividend) by another (the divisor) is based
on the rules for binary subtraction and
multiplication and Similar to decimal division
• Ex 1111101 ÷ 11001 = 101
•
51
Representation of Negative
numbers
• There are different ways of representing
negative numbers in a computer.
• Sign- magnitude representation
• One’s complement.
52
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.
53
• Example 1: represent (-127)10 using sign
magnitude in binary
• (-127)10 =11111111
• Example 2: represent (127)10 using sign
magnitude
• (127)10 =01111111
54
• In a 5- bit representation we use the first bit
for sign and the remaining 4- bits for the
magnitude.
• So using this 5 bit representation the range
of number that can be represented is from -
15 (11111) to 15(01111)
55
One’s complement
• In one’s complement representation, all
positive integers are represented in their
correct binary format.
• For example +3 is represented as usual by
00000011 using 8 bits
• The one’s complement representation of -3
is 11111100.
• Ex: +2 is 00000010
56
• -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.
• Ex1. add –3 and 3 with word size 4
• 3 = 0011
• -3=1100
• sum =1111 (=0)
57
• Ex2. Add -4 and +6
• - 4 is 11111011
• + 6 is 00000110
• the sum is (1) 00000001 the one in the
parenthesis is the external carry. Where 1
indicates a carry. The correct result should
be 2 or 00000010.
• In one’s complement addition and
subtraction, if there is an external carry it
should be added to get the correct result.
This indicates it requires additional circuitry58
for implementing this operation.
Two’s Complement Representation
59
• Ex: +3 is represented in signed binary as
• 00000011
• Its one’s complement representation is
• 11111100.
• The two’s complement is obtained by
adding one.
• 11111101.
60
• Ex let’s try addition.
• (3) 00000011
• + (5) +00000101
• (8) 0001000
• Ex2. Let’s try subtraction
• (3) 00000011
(-5) + 11111011
11111110 61
Character Representation
62
Extended Binary Coded Decimal
Interchange Code. (EBCDIC)
63
BCD (Binary Coded Decimal)
64
ASCII- 7(American Standard Code
for Information interchange)
• Used widely before the introduction of
ASCII-8 (the Extended ASCII). Uses 7 bits
to represent a character; with the seven bits,
27(or 128) different characters can be coded
(0000000-1111111)
65
ASCII -8
• It is the most widely used type of coding
scheme for Micro Computer system. 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
66
(00000000-11111111).
UNICODE
• UNICODE a subset of ASCII, which uses
two bytes (16 bits) for each character rather
than one byte. That means it can handle
216(65,536) character combinations
• It allows almost all the written languages of
the world to be represented a single
character set.
67