COA CH 2
COA CH 2
Arranged from the smallest to the largest, the units are called bit, byte and word. These units are
Byte: Byte is a group of eight bits. A nibble is a half byte. Bits 0 through 3 are called the low order
By: Bifa H 3
Binary Number System
A binary number system is used in the digital computers.
The decimal number system contains ten digits from 0 to 9(base 10).
The position in the decimal number system specifies the power of the
base (10). The 0 is the minimum value of the digit, and 9 is the maximum
value of the digit.
OExamples: (451)10, (189)10, (875)10, (103)10, (687)10.
By: Bifa H 5
Octal Number System
In the octal number system, there can be eight possibilities: "0", "1",
By: Bifa H 8
Binary to Decimal Conversion
Example 1: (10110.001)2
(10110.001)2=(1×16)+(0×8)+(1×4)+(1×2)+(0×1)+(0×1⁄2)+(0×1⁄4)+(1×1⁄8)
(10110.001)2=16+0+4+2+0+0+0+0.125
By: Bifa H 9
Binary to Octal Conversion
To convert a binary number to its equivalent octal number, follow these
steps:
1) Divide the binary number into groups of three bits each beginning from
right side. 111 =1x20
+1x2 1
+1x2 2
=7
2) Add 0s to the left, if last group is incomplete. 110 =0x2 0
+1x2 1
+1x22
=6
3) Convert each group into decimals. 101 =1x20+0x21+1x22 =5
011=1x20+1x21+0x22 =3
Example1: (111110101011.0011)2 to ()10
001=1x20+0x21+0x22 =1
1st step: 111 110 101 011.001 001 001 =0x2 0
+0x21
+1x2 2
=1
2nd step: we wrote the octal digits, which correspond to each pair
By: Bifa H 10
(111110101011.0011)2= (7653.11)8
Binary to Hexadecimal Conversion
To convert a binary number to its equivalent hexadecimal number, follow these
steps:
1) Divide the binary number into groups of four bits each beginning from right side.
2) Add 0s to the left, if last group is incomplete.
0101=1x2 +0x2 +1x2 +0x2 =5
0 1 2 3
3) Convert each group into decimals
1010=0x2 +1x2 +0x2 +1x2 =10=A
0 1 2 3
2nd step: we write the hexadecimal digits, which correspond to each pair.
(010110101011.0011)
By: Bifa H
2=(5AB.3)16
11
Decimal to Binary Conversion
To convert a decimal number to its equivalent binary number, follow
these steps:
1. Divide the number by 2 and store the remainder.
2. Divide the quotient by 2 and store the remainder.
3. Repeat these steps until quotient becomes 0. Example 1:
4. Write the remainders from bottom to top order.
This arrangement of remainder digits will be
the binary equivalent of the number.
Let us describe this conversion process
with decimal number 23.
By: Bifa H 12
Decimal to Binary Conversion
Example 2: (152.25)10 = ( )2 ?
Step 1: Divide the number 152 and
Step 2: Now, perform the
its successive quotients with base 2. multiplication of 0.25 and
Operation Quotient Remainder successive fraction with base 2.
152/2 76 0
Operation Result carry
76/2 38 0
0.25×2 0.50 0
38/2 19 0
0.50×2 0 1
19/2 9 1
9/2 4 1 (0.25)10=(.01)2
(152)10=(10011000)2
4/2 2 0
2/2 1 0 (152.25)10 =(10011000.01)2
By:
1/2 Bifa H 0 1 13
Decimal to Octal Conversion
To convert a decimal number to its equivalent octal number, follow these
steps:
1. Divide the number by 8 and store the remainder.
2. Divide the quotient by 8 and store the remainder.
Example 1:
3. Repeat these steps until quotient becomes 0.
4. Write the remainders from bottom to top order.
The steps are same as in decimal to
binary conversion with only one difference
that the number is divided by 8 because,
8 is the base in octal number system.
For example, 837 in decimal will be
By: Bifa H 14
equal to 1505 in octal.
Decimal to Octal Conversion
Example 2: (152.25)10 = ( )8 ?
Step 1: Divide the number 152 and
Step 2: Now, perform the
its successive quotients with base 8. multiplication of 0.25 and
Operation Quotient Remainder successive fraction with base 8.
152/8 19 0
Operation Result carry
19/8 2 3
0.25×8 0 2
2/8 0 2
(0.25)10=(2)8
(152)10=(230)8
So, the octal number of the decimal number
By: Bifa H
(152.25)10 = (230.2 )8 15
Decimal to Hexadecimal conversion
To convert a decimal number to its equivalent hexadecimal number, follow
these steps:
1. Divide the number by 16 and store the remainder.
2. Divide the quotient by 16 and store the remainder.
Example 1:
3. Repeat these steps until quotient becomes 0.
4. Write the remainders from bottom to top order.
The steps are same as in decimal to binary
conversion with only one difference that
the number is divided by 16 because,
16 is the base in hexadecimal number system.
For example, 1715 in decimal will be
By: Bifa H 16
equal to 6B3 in hexadecimal.
Decimal to Hexadecimal Conversion
Example 2: (152.25)10 = ( )16 ?
Step 1: Divide the number 152 and
Step 2: Now, perform the
its successive quotients with base 16. multiplication of 0.25 and
Operation Quotient Remainder successive fraction with base
152/16 9 8 16.
9/16 0 9 Operation Result carry
0.25×16 0 4
(152)10=(98)16
(0.25)10=(4)16
So, the Hexadecimal number of the decimal
By: Bifa H
number (152.25)10 = (98.4 )16 17
Octal to Decimal Conversion
The process of converting octal to decimal is the same as binary to
decimal.
The process starts from multiplying the digits of octal numbers with its
corresponding positional weights.
And lastly, we add all those products.
Example 1: (152.25)8 to ( )10
(152.25)8=(1×8 )+(5×8 )+(2×8 )+(2×8 )+(5×8 )
2 1 0 -1 -2
(152.25)8=64+40+2+(2×1⁄8)+(5×1⁄64)
(152.25)8=64+40+2+0.25+0.078125
(152.25)8=106.328125
By: Bifa H 18
So, the decimal number of the octal number 152.25 is 106.328125
Octal to Binary Conversion
The process of converting octal to binary is the reverse process of
binary to octal.
We write the three bits binary code of each octal number digit.
Example 1: (152.25)8 to ( )2
(152A.25)16=4096+1280+32+10+(2×1⁄16)+(5×1⁄256)
(152A.25)16=5418+0.125+0.125
(152A.25)16=5418.14453125
So, the decimal number of the hexadecimal number 152A.25
is 5418.14453125
By: Bifa H 22
Hexadecimal to Binary Conversion
The process of converting hexadecimal to binary is the reverse process
of binary to hexadecimal.
We write the four bits binary code of each hexadecimal number digit.
Example 1: (152A.25)16
We write the four-bit binary digit for 1, 5, 2, A and 2 5.
(152A.25)16=(0001 0101 0010 1010.0010 0101)2
So, the binary number of the hexadecimal number 152.25
is (1010100101010.00100101)2
By: Bifa H 23
Hexadecimal to Octal Conversion
In the first step, we will find the binary equivalent of the hexadecimal number.
Next, we have to make the pairs of three bits on both sides of the binary point.
Example 1: (152A.25)16
Step 1: We write the four-bit binary digit for 1, 5, 2, A, and 2 5.
(152A.25)16=(0001 0101 0010 1010.0010 0101)2
So, the binary number of hexadecimal number 152A.25
is (0011010101010.010101)2
Step 2: Then, we make pairs of three bits on both sides of the binary point.
001 010 100 101 010.001 001 010
Step 3: Then, we write the octal digit, which corresponds to each pair.
(001010100101010.001001010)2=(12452.112)8
By: Bifa H 24
So, the octal number of the hexadecimal number 152A.25 is 12452.112
Fixed and floating-point systems
Fixed-point systems
Fixed-point representation is convenient for representing numbers with bounded orders
of magnitude.
For instance, in a digital computer that uses 32 bits to represent numbers, the range of
integers that can be used is limited to ± (231-1), which is approximately ±1012.
For example, if given fixed-point representation is IIII.FFFF, then you can store
minimum value is 0000.0001 and maximum value is 9999.9999.
There are three parts of a fixed-point number representation: the sign field, integer
field, and fractional field.
By: Bifa H 25
Fixed-point systems
We can represent these numbers using:
Signed representation: range from -(2(k-1)-1) to (2(k-1)-1), for k bits.
1’s complement representation: range from -(2(k-1)-1) to (2(k-1)-1), for k bits.
2’s complementation representation: range from -(2(k-1)) to (2(k-1)-1), for k bits.
2’s complementation representation is preferred in computer system because of unambiguous
property and easier for arithmetic operations.
Example:- Assume number is using 32-bit format which reserve 1 bit for the sign, 15 bits for the
integer part and 16 bits for the fractional part.
Then, -43.625 is represented as following:
Where, 0 is used to represent +ve and 1 is used to represent -ve. 000000000101011 is 15 bit
binary value for decimal 43 and 1010000000000000 is 16 bit binary value for fractional
0.625.
By: Bifa H 26
Fixed-point systems
Advantages of Fixed Point Representation:
The advantage of using a fixed-point representation is performance
Integer representation and fixed point numbers are indeed close relatives.
Because of this, fixed point numbers can also be calculated using all the
arithmetic operations a computer can perform on integers.
They are just as simple and effective as computer integer arithmetic.
To conduct real number arithmetic using fixed point format, we can reuse all
the hardware designed for integer arithmetic.
Disadvantages of Fixed Point Representation:
Disadvantage is relatively limited range of values that they can represent.
Loss in range and precision when compared to representations of floating point
numbers.
By: Bifa H 27
Floating-point systems
This representation does not reserve a specific number of bits for the integer part or the
fractional part.
Instead it reserves a certain number of bits for the number (called the mantissa or
significand) and a certain number of bits to say where within that number the decimal
place sits (called the exponent).
The general form of a floating-point representation number N is
By: Bifa H 28
Floating-point systems
The mantissa and the exponent can be either positive or negative.
In digital computers, floating-point numbers consist of three parts:
A sign bit, an exponent part (representing the exponent on a power of 2), and a
fractional part called a significant (which is a fancy word for a mantissa).
The number of bits used for the exponent and significant depends on whether we would
like to optimize for range (more bits in the exponent) or precision (more bits in the
significant).
For the remainder of this section, we will use a 14-bit model with a 5-bit exponent, an 8-
bit significant, and a sign bit as depicted below
A 0 on the sign bit indicates the integer is positive and a 1 indicates the integer is a
negative.
By: Bifa H 29
Floating-point systems
The floating point representation is more flexible.
Any non-zero number can be represented in the normalized form of
±(1.b1b2b3 ...)2x2 This is normalized form of a number x.
n
Let’s say that we wish to store the decimal number 17 in our model.
We know That 17 = 17.0 X100 = 1.7 X 101 = 0.17 X 102.
Analogously, in binary, 1710 = 100012 X 20 = 1000.12 X21 = 100.012 X22 =
10.0012 X2 = 1.00012 X2 =0.100012 X 2
3 4 5.
If we use this last form, our fractional part will be 10001000 and our exponent
will be 00101, as shown here:
By: Bifa H 30
Signed and two’s-complement representations
Signed Numbers:
Negative integers in binary number systems must be encoded using signed number
representations.
In mathematics, negative numbers are denoted by a minus sign (“-“) before them.
In contrast, numbers are exclusively represented as bit sequences in computer hardware,
with no additional symbols.
The signed numbers are represented in three ways.
The signed bit makes two possible representations of zero (positive (0) and negative
(1)), which is an ambiguous representation.
The third representation is 2's complement representation in which no double
representation of zero is possible, which makes it unambiguous representation.
By: Bifa H 31
Signed Numbers:
There are the following types of representation of signed binary
numbers:
a) Sign-Magnitude form
In sign-magnitude form, the number’s sign is represented by the
MSB (Most Significant Bit also called as Leftmost Bit), while
its magnitude is shown by the remaining bits
In the case of 8-bit representation Leftmost bit is the sign bit and
remaining bits are magnitude bit.
55 = 00110111
10 2
By: Bifa H 32
−55 = 10110111
10 2
Signed Numbers:
There are the following types of representation of signed binary numbers:
b) 1's complement
The complement is used for representing the negative decimal number in binary
form.
We can find the 1's complement of the binary number by simply inverting the
given number.
For finding 1's complement of the binary number, we can implement the logic
circuit also by using NOT gate.
We use NOT gate for each bit of the binary number. So, if we want to
implement the logic circuit for 5-bit 1's complement, five NOT gates will be
used.
Example 1: the 1's complement of the number 11010.1101 comes out
By: Bifa H 33
00101.0010
Signed Numbers:
c) 2's complement
For finding 2's complement of the binary number, we will first find
the 1's complement of the binary number and then add 1 to the
least significant bit of it.
For example, if we want to calculate the 2's complement of the
number 1011001, then firstly, we find the 1's complement of the
number that is 0100110 and add 1 to the LSB.
by adding 1 to the LSB, the number will be
(0100110)+1=0100111.
We can also create the logic circuit using OR, AND, and NOT
By: Bifa H 34
gates.
Signed Numbers:
c) 2's complement
The 1's complement is an ambiguous technique, and 2's complement is an unambiguous
technique.
Let's see an example to understand how we can calculate the 2's complement in signed binary
number representation.
Example 1: +6 and -6
The +6 is represented in the 5-bit register as 0 0110.
The -6 is represented in the 5-bit register in the following way:
1. +6 = 0 0110
2. Now, find the 1's complement of the number 0 0110, i.e. 1 1001.
3. Now, add 1 to its LSB. When we add 1 to the LSB of 11001,
the newly generated number comes out 11010.
Here, the sign bit is one which means the number is the
negative number.
By: Bifa H 35
Representation of nonnumeric data
Binary Coded Decimal (BCD)
The BCD (Binary Coded Decimal), also called packed decimal.
In order to have representations for the ten digits of the decimal
number system, we need a four bit string.
Notes: BCD is not equivalent to binary.
When stored in an 8-bit byte, the upper nibble is called the zone and
the lower part is called the digit.
The high-order nibble in a BCD byte is used to hold the sign, which
can have one of three values:
An unsigned number is indicated with 1111; a positive number is
By: Bifa H 36
indicated with 1100; and a negative number is indicated with 1101.
Representation of nonnumeric data
Binary Coded Decimal (BCD)
Coding for BCD numbers is shown below
By: Bifa H 37
Representation of nonnumeric data
Converting from decimal to BCD
Each digit is converted to its 4-bit BCD equivalent.
Example: the number 319 would be represented in 12-bits as follows:
8 4 2 1 8 4 2 1 8 4 2 1
0 0 1 1 0 0 0 1 1 0 0 1
3 1 9
Converting from BCD to decimal
Each group of 4-bits are converted into the equivalent denary digit.
Example: The 12-bit binary coded decimal number 0110 1000 0011 is denary
683 as shown below 8 4 2 1 8 4 2 1 8 4 2 1
0 1 1 0 1 0 0 0 0 0 1 1
6 8 3
By: Bifa H 38
Representation of nonnumeric data
EBCDIC(Extended Binary Coded Decimal Interchange Code)
The EBCDIC code is shown below
By: Bifa H 39
Representation of nonnumeric data
EBCDIC(Extended Binary Coded Decimal Interchange Code)
The EBCDIC code is shown below
By: Bifa H 40
Representation of nonnumeric data
ASCII (American Standard Code for Information Interchange)
ASCII defines codes for 32 control characters, 10 digits, 52 letters (upper- and
lowercase), 32 special characters (such as $ and #), and the space character. The high-
order (eighth) bit was intended to be used for parity.
Parity is the most basic of all error detection schemes.
A parity bit is turned “on” or “off” depending on whether the sum of the other bits in
the byte is even or odd.
For example, if we decide to use even parity and we are sending an ASCII A, the lower
7 bits are 100 0001.
Because the sum of the bits is even, the parity bit would be set to off and we would
transmit 0100 0001.
Similarly, if we transmit an ASCII C, 100 0011, the parity bit would be set to on before
we sent
By: Bifa H
the 8-bit byte, 1100 0011. 41
Parity can be used to detect only single-bit errors.
Representation of nonnumeric data
ASCII (American Standard Code for Information Interchange)
ASCII is a 7-bit coding scheme
ASCII codes are shown below
By: Bifa H 42
Representation of nonnumeric data
ASCII (American Standard Code for Information Interchange)
ASCII codes are shown below
By: Bifa H 43
Representation of nonnumeric data
Unicode
Unicode is a 16-bit alphabet that is downward compatible with ASCII and the
Latin-1 character set.
Because the base coding of Unicode is 16 bits, it has the capacity to encode
the majority of characters used in every language of the world.
Unicode is currently the default character set of the Java programming
language.
Ultimately, the acceptance of Unicode by all manufacturers will depend on
how aggressively they wish to position themselves as international players and
how inexpensively disk drives can be produced to support an alphabet with
double the storage requirements of ASCII or EBCDIC.
By: Bifa H 44
Representation of nonnumeric data
Unicode
The Unicode code space consists of five parts, as shown in the figure below
By: Bifa H 45
Representation of nonnumeric data
Unicode
By: Bifa H 46
Representation of nonnumeric data
Unicode
The Unicode code space consists of five parts, as shown in
the figure below
By: Bifa H 47
Representation of records and arrays
Arrays
Consider the array of integers:
A=[10, 25, 4, 76, 8]
Here N=5, number of elements in the array.
In an 8-bit machine, it is represented as;
Consider the two-dimensional array:
Representation of Strings
Strings are arrays of characters.
Each character is represented as a byte in either ASCII or EBCDIC format.
Representation of the string COMPUTER is shown below using the 32-bit machine
architecture
The end of the string is usually denoted by a special character called null, which is
By: Bifa H
represented as ‘‘\0.’’ 49
Representation of records and arrays
Records
A record typically contains one or more fields.
The data in these fields may be of different types.
The number of bits needed to represent each field may vary.
Consider for instance, the records of students in a university containing the fields :
ID, Name, Phone number, and GPA.
The ID field could be treated as either numeric or alphanumeric depending on the
processing performed on it.
The Name field is a string , and might b e partitioned into subfields for first, last, and
middle names.
The Phone number could be treated as numeric or alphanumeric, and the GPA is a
floating point number.
The detailed characteristic of the record indicating the field lengths and the type of data in
By: Bifa H 50
each field needs to be maintained to access data appropriately.