You are on page 1of 28

13

2 | Number Systems and Data Representation 1


3

Unit II: Number Systems and


Data Representation

2.0 Learning Outcomes

At the end of this lesson packet, the students are expected to


attain the following intended learning outcomes:
2.0.1 Describe the fundamentals of numerical data representation and
manipulation in digital computers.
2.0.2 Master the skill of converting between various radix systems.

2.1 Introduction

Understanding binary number, 1s and 0s

Data, in principal, is stored in 1s and 0s. Computers make


use of data structures that describe a specific sequence for data to
be organized. This allows the computer to understand how the
different bits of data are related and to interpret the data correctly.

2.2 Discussions and Assessments

2.2.1 Number Systems and Data Representation

In order to communicate data and instructions, data such as


numbers, letters, characters, special symbols, sounds/phonics, and images
are converted into computer-readable form (binary). Once the processing of
this data is complete, it is then converted into a format that people can
understand. The processed data becomes meaningful information.

The information becomes knowledge when it is understood and used


by people for different purposes.

2.2.1.1 Digital Systems and Switching Circuits

Logic circuits are the basis for modern digital computer systems. To
appreciate how computer systems operate you will need to understand
digital logic and Boolean algebra.

Given a specification constraining the input and output relation of a


digital system, we’ll learn how to design a logic circuit that implements the
specification.
1 | Number Systems and Data Representation
14
1
4

Switching Theory allows us to understand the operation and


relationship between Boolean Algebra and two-level logic functions with
regards to Digital Logic Gates. Switching theory can be used to further
develop the theoretical knowledge and concepts of digital circuits when
viewed as an interconnection of input elements producing an output state
or condition.
Digital logic gates whose inputs and output can switch between two
distinct logical values of 0 and 1, can be defined mathematically simply by
using Boolean Algebra. But we can also represent the two digital logic states
of HIGH or LOW, “1” or “0”, “ON” or “OFF”, and TRUE or FALSE, using
electromechanical contacts in the form of switches or relays as a logic circuit
element. The implementation of switching functions in digital logic circuits
is nothing new, but it can give us a better understanding of how a single
digital logic gate works.
Digital logic gates are the basic building blocks from which all digital
electronic circuits and microprocessor based systems are made. They can be
interconnected together to form either combinational logic circuits which are
fully dependent on any external input signals applied to it, or sequential logic
circuits which are dependent on its present stable state, feedback of its
output, as well as any external input signals that may trigger a switching
event.
Here in this simple example, the lamp (L) is connected to the battery
supply, VS via the normally-open switch, S1. If switch S1 is not-pressed and
therefore open, no current (I) flows so the lamp will be “OFF” and not
illuminated. If switch S1 is pressed closing it, then current flows around the
circuit and the lamp (L) will be “ON” and illuminated. Under normal steady
state conditions the switch is permanently “open” so the lamp is “OFF”.

We can use switching algebra to describe the operation of the circuit


containing the switch, S1. For example, if we label the normally-open switch
as a variable with the letter “A“, then when the switch is open, that is “A”
is not-pressed, we can define the value of “A” as being “0”. Likewise, when
the switch is closed, that is “A” is pressed, we can define the value of “A”
as being “1”. This switching algebra theory is true for ALL normally-open
switch configurations.

/mmediza
1 | Number Systems and Data Representation
15
1
5

We can develope this switching theory idea further by saying when


the lamp is “ON” (illuminated), its switching alegebra variable will be “1”,
and when the lamp is “OFF” (not illuminated), its switching algebra
variable will be “0”. Thus, when the switch is pressed (activated) the lamp
is “ON”, so “A” = 1 and “L” = 1, and when the switch is not-pressed
(unactivated) the lamp is “OFF”, so “A” = 0 and “L” = 0. Therefore we can
correctly say that for the switching theory of the lamp, L = A as shown in
the truth table.
The type of switch used in the above example is called a normally-
open, make-contact switch as the have to physically make it for the switch to
be considered closed (A = 1). But there is another type of switch
arrangement which is the exact opposite in operation of the switch above
called a normally-closed, break-contact switch which is constantly closed.

If we now connect switches, S1 and S2 together in parallel as shown,


how would is arrangement affect the switching function of the circuit and
the illumination of the lamp.

The Switching Theory of Parallel Switches

The switching circuit now consists of the two switches in parallel


with the voltage source, VS and the lamp. As before, when either switch is
open, that is not-pressed, we can define the value of “A” as being “0” and
“B” as also being “0”. Likewise, when either switch is closed or pressed, we
can define the value of “A” as being “1” or “B” as being “1”.
As before, with two switches, S1 and S2, or “A” and “B”, there are
four possible combinations of the Boolean variables “A” and “B” required
to illuminate the lamp. The corresponding states are: “A” is open and “B”
is closed, or “A” is closed and “B” is open, both “A” and “B” are open, or

/mmediza
1 | Number Systems and Data Representation
16
1
6

both closed at the same time. Then we can define these switching operations
in the following switching theory truth table.

Parallel Switch Truth Table

The truth table shows that the lamp will only be “ON” and
illuminated when EITHER switch, A OR switch, B are pressed and closed
as pressing either switch will cause current to flow because there will
always be a conducting path available for the lamp through whichever
closed switch.
This therefore proves that when two switches S1 and S2 are connected
together in parallel, the switching condition that allows current (I) to flow
and make the lamp illuminate is when any one of the switches, or both are
closed. This gives the boolean expression of: L = A or B.
In Boolean Algebra terms, this expression is that of the OR function
which is denoted by a addition or plus sign, (+) between the variables giving
us the Boolean expression of: L = A+B.
Thus when switches are connected together in parallel their
switching theory and operation is the same as for the digital logic “OR” gate
because if both inputs are “0”, then the output is “0”, otherwise the output
is “1” as shown..
Digital Logic OR Gate

Thus if input “A” is OR’ed with input “B” it produces output “Q”,
and in switching terms, the OR function is referred to as the Boolean
Algebra logical addition function.
Switching Theory can be used to implement Boolean expressions as
well as digital logic gates. Ad we have seen above, in switch contact terms,
the boolean expression using a dot (.) is interpreted as a series connection
for Boolean multiplication, while a plus sign (+) is interpreted as a pair of
parallel branches for Boolean addition.

/mmediza
1 | Number Systems and Data Representation
17
1
7

Implement the following Boolean function of Q = A(B+C) using


switches to illuminate a lamp (or LED). Also show the equivalent digital
logic circuit.
Switch Implementation

Logic Gate Implementation

Indempotent Law of Switches


Thus far we have seen how to connect two switches together either
in series or parallel to illuminate a lamp. But what if the two switches
representing a Boolean AND function or an OR function (operations of
multiplication and sum) are of the same single Boolean variable, A. In
Boolean Algebra there are various laws and theroems which can be used to
define the mathematics of logic circuits. One such theorem is known by the
name of indempotent law.
Idempotent laws used in switching theory states that AND-ing or
OR-ing a variable with itself will produce the original variable. For example
variable “A” AND’ed with “A” will give “A”, likewise variable “A” OR’ed
with “A” will give “A”, allowing us to simplify our switching circuits and
we can demonstrate this below.

Indempotent Law of AND Function

/mmediza
1 | Number Systems and Data Representation
18
1
8

Indempotent Law of OR Function

The representation of “AND” and “OR” functions using normally-


open switches are easy to construct, easy to understand, and form the basic
building blocks for most combinational logic circuits. Thus given any
Boolean expression or logic function, it is possible to use switching theory
to implement it, after all, logic design is about using switches or
electromechanical devices such as relays.
Another useful gates is inverting NOT gates are single input devices
which have an output level that is normally at logic level “1” and goes
“LOW” to a logic level “0” when its single input is at logic level “1”, in other
words it “inverts” (complements) its input signal. The output from a NOT
gate only returns “HIGH” again when its input is at logic level “0” giving
us the Boolean expression of: A = Q.
Then we can define the operation of a single input digital logic NOT gate
as being:

“If A is NOT true, then Q is true”

Transistor NOT Gate


A simple 2-input logic NOT gate can be constructed using a RTL Resistor-
transistor switches as shown below with the input connected directly to
the transistor base. The transistor must be saturated “ON” for an inverted
output “OFF” at Q.

/mmediza
1 | Number Systems and Data Representation
19
1
9

Logic NOT Gates are available using digital circuits to produce the
desired logical function. The standard NOT gate is given a symbol whose
shape is of a triangle pointing to the right with a circle at its end. This circle
is known as an “inversion bubble” and is used in NOT, NAND and NOR
symbols at their output to represent the logical operation of the NOT
function. This bubble denotes a signal inversion (complementation) of the
signal and can be present on either or both the output and/or the input
terminals.

The Logic NOT Gate Truth Table

Symbol Truth Table

A Q

0 1

1 0
Inverter or NOT Gate

Boolean Expression Q = not A or A Read as inverse of A gives Q

Logic NOT gates provide the complement of their input signal and
are so called because when their input signal is “HIGH” their output state
will NOT be “HIGH”. Likewise, when their input signal is “LOW” their
output state will NOT be “LOW”. As they are single input devices,
logic NOT gates are not normally classed as “decision” making devices or
even as a gate, such as the AND or OR gates which have two or more logic
inputs. Commercial available NOT gates IC’s are available in either 4 or 6
individual gates within a single IC package.
The “bubble” (o) present at the end of the NOT gate symbol above
denotes a signal inversion (complementation) of the output signal. But this
bubble can also be present at the gates input to indicate an active-LOW input.
This inversion of the input signal is not restricted to the NOT gate only but
can be used on any digital circuit or gate as shown with the operation of
inversion being exactly the same whether on the input or output terminal.
The easiest way is to think of the bubble as simply an inverter.

/mmediza
1 | Number Systems and Data Representation
20
2
0

Rule in Boolean Algebra

Following are the important rules used in Boolean algebra.


 Variable used can have only two values. Binary 1 for HIGH and
Binary 0 for LOW.
 Complement of a variable is represented by an overbar (-). Thus,

complement of variable B is represented as . Thus if B = 0


then = 1 and B = 1 then = 0.
 ORing of the variables is represented by a plus (+) sign between
them. For example ORing of A, B, C is represented as A + B + C.
 Logical ANDing of the two or more variable is represented by
writing a dot between them such as A.B.C. Sometime the dot may
be omitted like ABC.

There are six types of Boolean Laws.


1. Commutative law
Any binary operation which satisfies the following expression is
referred to as commutative operation.

Commutative law states that changing the sequence of the variables


does not have any effect on the output of a logic circuit.

2. Associative law
This law states that the order in which the logic operations are
performed is irrelevant as their effect is the same.

3. Distributive law
Distributive law states the following condition.

4. AND law
These laws use the AND operation. Therefore they are called
as AND laws.

5. OR law
These laws use the OR operation. Therefore they are called as OR laws.

6. INVERSION law
This law uses the NOT operation. The inversion law states that double
inversion of a variable results in the original variable itself.

/mmediza
1 | Number Systems and Data Representation
21
2
1

2.2.1.2 Number Systems and Conversion

The technique to represent and work with numbers is called number


system. Decimal number system is the most common number system. Other
popular number systems include binary number system, octal number
system, hexadecimal number system, etc.

Decimal Number System

Decimal number system is a base 10 number system having 10 digits


from 0 to 9. This means that any numerical quantity can be represented using
these 10 digits. Decimal number system is also a positional value system. This
means that the value of digits will depend on its position. Let us take an
example to understand this.
Say we have three numbers – 734, 971 and 207. The value of 7 in all three
numbers is different−

 In 734, value of 7 is 7 hundreds or 700 or 7 × 100 or 7 × 102


 In 971, value of 7 is 7 tens or 70 or 7 × 10 or 7 × 101
 In 207, value 0f 7 is 7 units or 7 or 7 × 1 or 7 × 100

The weightage of each position can be represented as follows −

In digital systems, instructions are given through electric signals;


variation is done by varying the voltage of the signal. Having 10 different
voltages to implement decimal number system in digital equipment is
difficult. So, many number systems that are easier to implement digitally have
been developed. Let’s look at them in detail.

Binary Number System

The easiest way to vary instructions through electric signals is two-


state system – on and off. On is represented as 1 and off as 0, though 0 is not
actually no signal but signal at a lower voltage. The number system having
just these two digits – 0 and 1 – is called binary number system.

Each binary digit is also called a bit. Binary number system is also
positional value system, where each digit has a value expressed in powers of
2, as displayed here.

/mmediza
1 | Number Systems and Data Representation
22
2
2

In any binary number, the rightmost digit is called least significant bit
(LSB) and leftmost digit is called most significant bit (MSB).

The decimal equivalent of this number is sum of product of each digit


with its positional value.

110102 = 1×24 + 1×23 + 0×22 + 1×21 + 0×20


= 16 + 8 + 0 + 2 + 0
= 2610

Computer memory is measured in terms of how many bits it can


store. Here is a chart for memory capacity conversion.

 1 byte (B) = 8 bits


 1 Kilobytes (KB) = 1024 bytes
 1 Megabyte (MB) = 1024 KB
 1 Gigabyte (GB) = 1024 MB
 1 Terabyte (TB) = 1024 GB
 1 Exabyte (EB) = 1024 PB
 1 Zettabyte = 1024 EB
 1 Yottabyte (YB) = 1024 ZB

Octal Number System

Octal number system has eight digits – 0, 1, 2, 3, 4, 5, 6 and 7. Octal


number system is also a positional value system with where each digit has
its value expressed in powers of 8, as shown here −

Decimal equivalent of any octal number is sum of product of each digit with
its positional value.

7268 = 7×82 + 2×81 + 6×80


= 448 + 16 + 6
= 47010

/mmediza
1 | Number Systems and Data Representation
23
2
3

Hexadecimal Number System

Hexadecimal number system has 16 symbols – 0 to 9 and A to F where


A is equal to 10, B is equal to 11 and so on till F. Hexadecimal number system
is also a positional value system with where each digit has its value expressed
in powers of 16, as shown here −

Decimal equivalent of any hexadecimal number is sum of product of


each digit with its positional value.

27FB16 = 2×163 + 7×162 + 15×161 + 10×160


= 8192 + 1792 + 240 +10
= 1023410

Number System Relationship

The following table depicts the relationship between decimal, binary,


octal and hexadecimal number systems.

HEXADECIMAL DECIMAL OCTAL BINARY


0 0 0 0000
1 1 1 0001
2 2 2 0010
3 3 3 0011
4 4 4 0100
5 5 5 0101
6 6 6 0110
7 7 7 0111
8 8 10 1000
9 9 11 1001
A 10 12 1010
B 11 13 1011
C 12 14 1100
D 13 15 1101
E 14 16 1110
F 15 17 1111

/mmediza
1 | Number Systems and Data Representation
24
2
4

ASCII
Besides numerical data, computer must be able to handle alphabets,
punctuation marks, mathematical operators, special symbols, etc. that form
the complete character set of English language. The complete set of characters
or symbols are called alphanumeric codes. The complete alphanumeric code
typically includes –

 26 upper case letters


 26 lower case letters
 10 digits
 7 punctuation marks
 20 to 40 special characters

Now a computer understands only numeric values, whatever the


number system used. So all characters must have a numeric equivalent called
the alphanumeric code. The most widely used alphanumeric code is
American Standard Code for Information Interchange (ASCII). ASCII is a 7-
bit code that has 128 (27) possible codes.

ISCII

ISCII stands for Indian Script Code for Information Interchange. IISCII
was developed to support Indian languages on computer. Language
supported by IISCI include Devanagari, Tamil, Bangla, Gujarati, Gurmukhi,
Tamil, Telugu, etc. IISCI is mostly used by government departments and

/mmediza
1 | Number Systems and Data Representation
25
2
5

before it could catch on, a new universal encoding standard


called Unicode was introduced.

Unicode

Unicode is an international coding system designed to be used with


different language scripts. Each character or symbol is assigned a unique
numeric value, largely within the framework of ASCII. Earlier, each script
had its own encoding system, which could conflict with each other.

In contrast, this is what Unicode officially aims to do − Unicode


provides a unique number for every character, no matter what the platform, no
matter what the program, no matter what the language.

Converting Between Various Radix Systems

As you know decimal, binary, octal and hexadecimal number systems


are positional value number systems. To convert binary, octal and
hexadecimal to decimal number, we just need to add the product of each digit
with its positional value. Here we are going to learn other conversion among
these number systems.

Decimal to Binary

Decimal numbers can be converted to binary by repeated division of


the number by 2 while recording the remainder. Let’s take an example to see
how this happens.

The remainders are to be read from bottom to top to obtain the binary
equivalent.

Division Remainder
43/2 = 21 1
21/2 = 10 1
10/2 = 5 0
5/2 = 2 1
2/2 = 1 0
1/2 = 0 1

4310 = 1010112

/mmediza
1 | Number Systems and Data Representation
26
2
6

Decimal to Octal

Decimal numbers can be converted to octal by repeated division of


the number by 8 while recording the remainder. Let’s take an example to
see how this happens.

Reading the remainders from bottom to top, 47310 = 7318

Decimal to Hexadecimal

Decimal numbers can be converted to octal by repeated division of the


number by 16 while recording the remainder. Let’s take an example to see
how this happens.

Reading the remainders from bottom to top we get, 42310 = 1A716

Binary to Octal and Vice Versa

To convert a binary number to octal number, these are the steps:


 Starting from the least significant bit, make groups of three bits.
 If there are one or two bits less in making the groups, 0s can be
added after the most significant bit
 Convert each group into its equivalent octal number

Let’s take an example to understand this.

101100101012 = 26258

/mmediza
1 | Number Systems and Data Representation
27
2
7

To convert an octal number to binary, each octal digit is converted to its


3-bit binary equivalent according to this table.

Octal Digit 0 1 2 3 4 5 6 7

Binary Equivalent 000 001 010 011 100 101 110 111

546738 = 1011001101110112

Binary to Hexadecimal

To convert a binary number to hexadecimal number, these are the


steps:
 Starting from the least significant bit, make groups of four bits.
 If there are one or two bits less in making the groups, 0s can be added
after the most significant bit.
 Convert each group into its equivalent octal number.

Let’s take an example to understand this.

101101101012 = DB516
To convert an octal number to binary, each octal digit is converted to
its 3-bit binary equivalent.

/mmediza
1 | Number Systems and Data Representation
28
2
8

2.2.1.3 Binary Arithmetic

Binary arithmetic is essential part of all the digital computers and many
other digital system.

Binary Addition

It is a key for binary subtraction, multiplication, division. There are


four rules of binary addition.

In fourth case, a binary addition is creating a sum of (1 + 1 = 10) i.e. 0 is


written in the given column and a carry of 1 over to the next column.

Example: Addition

Binary Subtraction

Subtraction and Borrow, these two words will be used very frequently
for the binary subtraction. There are four rules of binary subtraction.

/mmediza
1 | Number Systems and Data Representation
29
2
9

Example: Subtraction

Binary Multiplication

Binary multiplication is similar to decimal multiplication. It is simpler


than decimal multiplication because only 0s and 1s are involved. There are
four rules of binary multiplication.

Example: Multiplication

/mmediza
1 | Number Systems and Data Representation
30
3
0

Binary Division

Binary division is similar to decimal division. It is called as the long


division procedure.

Example: Division

2.2.1.4 Representation of Negative Numbers

Negative numbers can be distinguishable with the help of extra bit or


flag called sign bit or sign flag in Binary number representation system for
signed numbers. It is not possible to add minus or plus symbol in front of a
binary number because a binary number can have only two symbol either 0 or
1 for each position or bit. That’s why we use this extra bit called sign bit or sign
flag. The value of sign bit is 1 for negative binary numbers and 0 for positive
numbers.
When an integer binary number is positive, the sign is represented by
0 and the magnitude by a positive binary number. When the number is
negative, the sign is represented by 1 but the rest of the number may be
represented in one of three possible ways: Sign-Magnitude method, 1’s
Complement method, and 2’s complement method. These are explained as
following below.

1). Signed Magnitude Method:

In this method, number is divided into two parts: Sign bit and
Magnitude. If the number is positive then sign bit will be 0 and if number is
negative then sign bit will be 1. Magnitude is represented with the binary form
of the number to be represented.

/mmediza
1 | Number Systems and Data Representation
31
3
1

Example: Let we are using 5 bits register. The representation of -5 to


+5 will be as follows:

Range of Numbers: For k bits register, MSB will be sign bit and (k-1)
bits will be magnitude. Positive largest number that can be stored is (2 (k-1)-1)
and negative lowest number that can be stored is -(2(k-1)-1).

Note: Drawback of this system is that 0 has two different representation one is
-0 (e.g., 1 0000 in five bit register) and second is +0 (e.g., 0 0000 in five bit
register).

2). 1’s Complement Method:

Positive numbers are represented in the same way as they are


represented in sign magnitude method. If the number is negative then it is
represented using 1’s complement. First represent the number with positive
sign and then take 1’s complement of that number.

Example: Let we are using 5 bits register. The representation of -5 and +5 will
be as follows:

+5 is represented as it is represented in sign magnitude method. -5 is


represented using the following steps:

(i) +5 = 0 0101
(ii) Take 1’s complement of 0 0101 and that is 1 1010. MSB is 1 which
indicates that number is negative. MSB is always 1 in case of negative
numbers.

Range of Numbers: For k bits register, positive largest number that can be
stored is (2(k-1)-1) and negative lowest number that can be stored is -(2(k-1)-1).

/mmediza
1 | Number Systems and Data Representation
32
3
2

Note: Drawback of this system is that 0 has two different representation one is
-0 (e.g., 1 1111 in five bit register) and second is +0 (e.g., 0 0000 in five bit
register).

3). 2’s Complement Method:

Positive numbers are represented in the same way as they are


represented in sign magnitude method. If the number is negative then it is
represented using 2’s complement. First represent the number with positive
sign and then take 2’s complement of that number.

Example: Let we are using 5 bits registers. The representation of -5 and +5 will
be as follows:

+5 is represented as it is represented in sign magnitude method. -5 is


represented using the following steps:

(i) +5 = 0 0101
(ii) Take 2’s complement of 0 0101 and that is 1 1011. MSB is 1 which
indicates that number is negative. MSB is always 1 in case of negative
numbers.

Range of Numbers: For k bits register, positive largest number that can be
stored is (2(k-1)-1) and negative lowest number that can be stored is -(2(k-1)).

The advantage of this system is that 0 has only one representation for
-0 and +0. Zero (0) is considered as always positive (sign bit is 0) in 2’s
complement representation. Therefore, it is unique or unambiguous
representation.

/mmediza
1 | Number Systems and Data Representation
33
3
3

These are representation method for signed binary numbers.

2.2.1.4.1 Addition of 2’s Complement Numbers

There are difference scenario for addition of two binary numbers using
2’s complement. These are explained as following below.

Case-1 − Addition of positive and negative number when positive number has greater
magnitude:

When positive number has greater magnitude, then take simply 2’s
complement of negative number and carry bit 1 is dropped and this result
will be positive number.

Example: Add 1110 and -1101.

So, take 2’s complement of 1101, which will be 0011, then add with
given number. So, 1110+0011=1 0001, and carry bit 1 is dropped and this
result will be positive number, i.e., +0001.

Note: That if the register size is big then use sign extension method of MSB
bit to preserve sign of number.

Case-2 − Addition of positive and negative number when negative number has
greater magnitude:

When the negative number has greater magnitude, then take 2’s
complement of negative number and add with given positive number. Since
there will not be any end-around carry bit, so take 2’s complement of the
result and this result will be negative.

Example: Add 1010 and -1100 in five-bit registers.

Note: That there are five-bit registers, so these new numbers will have 01010
and -01100. Now take 2’s complement of 01100 which will be 10100 and
add 01010+10100=11110. Then take 2’s complement of this result, which will
be 00010 and this will be negative number, i.e., -00010, which is the answer.

/mmediza
1 | Number Systems and Data Representation
34
3
4

Case-3 − Addition of two negative numbers:

You need to take 2’s complement for both numbers, then add these 2’s
complement of numbers. Since there will always be end-around carry bit, so
it is dropped. Now, take 2’s complement also of previous result, so this will
be negative number.
Alternatively, you can add both of these Binary numbers and take
result which will be negative only.
Example: add -1010 and -0101 in five bit-register.
These five bit numbers are -01010 and -00101. Add 2’s complements of
these numbers, 10110+11011 =1 10001. Since, there is a carry bit 1, so it is
dropped. Now take the 2’s complement of this result, which will be 01111 and
this number is negative, i.e, -01111, which is answer.
Note: That 2’s complement arithmetic operations are much easier than 1’s
complement because of there is no addition of end-around-carry-bit.

2.2.1.4.2 Addition of 1’s Complement Numbers

There are difference scenario for addition of two binary numbers


using 1’s complement. These are explained as following below.

Case-1: Addition of positive and negative number when positive number has greater
magnitude:

When positive number has greater magnitude, then take simply 1’s
complement of negative number and the end-around carry of the sum is
added to the least significant bit (LSB).

Example: Add 1110 and -1101.

So, take 1’s complement of 1101, which will be 0010, then add with
given number. So, 1110+0010=1 0000 , then add this carry bit to the LSB,
0000+1=0001 , which is the answer.

Note: That if the register size is big then fill the same value of MSB to preserve
sign magnitude for inputs and output.

Case-2: Addition of positive and negative number when negative number has greater
magnitude:

When the negative number has greater magnitude, then take 1’s
complement of negative number and add with given positive number. Since

/mmediza
1 | Number Systems and Data Representation
35
3
5

there will not be any end-around carry bit, so take 1’s complement of the
result and this result will be negative.

Example: Add 1010 and -1100 in five-bit registers.

Note: That there are five-bit registers, so these new numbers will be 01010 and
-01100.

Now take 1’s complement of 01100 which will be 10011 and


add 01010+10011=11101 . Then take 1’s complement of this result, which will
be 00010 and this will be negative number, i.e., -00010, which is the answer.

Case-3: Addition of two negative numbers:

You need to take 1’s complement for both numbers, then add these
1’s complement of numbers. Since there will always be end-around carry bit,
so add this again to the MSB of result. Now, take 1’s complement also of
previous result, so this will be negative number. Alternatively, you can add
both negative number directly, and get this result which will be negative only.

Example: add -1010 and -0101 in five bit-register.

These five bit numbers are -01010 and -00101. Add complements of
these numbers, 10101+11010 =1 01111 . Since, there is a carry bit 1, so add this
to the LSB of result, i.e., 01111+1=10000 . Now take the 1’s complement of this
result, which will be 01111 and this number is negative, i.e, -01111, which is
answer.

Note: That end-around-carry-bit addition occurs only in 1’s complement


arithmetic operations but not in 2’s complement arithmetic operations.

2.2.1.5 Binary Codes

In the coding, when numbers, letters or words are represented by a


specific group of symbols, it is said that the number, letter or word is being
encoded. The group of symbols is called as a code. The digital data is
represented, stored and transmitted as group of binary bits. This group is
also called as binary code. The binary code is represented by the number as
well as alphanumeric letter.

Following is the list of advantages that binary code offers.


 Binary codes are suitable for the computer applications.
 Binary codes are suitable for the digital communications.
 Binary codes make the analysis and designing of digital circuits if we
use the binary codes.

/mmediza
1 | Number Systems and Data Representation
36
3
6

 Since only 0 & 1 are being used, implementation becomes easy.

The codes are broadly categorized into following four categories.


 Weighted Codes
 Non-Weighted Codes
 Binary Coded Decimal Code
 Alphanumeric Codes
 Error Detecting Codes
 Error Correcting Codes

Weighted Codes

Weighted binary codes are those binary codes which obey the
positional weight principle. Each position of the number represents a specific
weight. Several systems of the codes are used to express the decimal digits 0
through 9. In these codes each decimal digit is represented by a group of four
bits.

Non-Weighted Codes

In this type of binary codes, the positional weights are not assigned.
The examples of non-weighted codes are Excess-3 code and Gray code.

Excess-3 code

The Excess-3 code is also called as XS-3 code. It is non-weighted code


used to express decimal numbers. The Excess-3 code words are derived from
the 8421 BCD code words adding (0011)2 or (3)10 to each code word in 8421.
The excess-3 codes are obtained as follows −

/mmediza
1 | Number Systems and Data Representation
37
3
7

Example:

Gray Code

It is the non-weighted code and it is not arithmetic codes. That


means there are no specific weights assigned to the bit position. It has a very
special feature that, only one bit will change each time the decimal number
is incremented as shown in fig. As only one bit changes at a time, the gray
code is called as a unit distance code. The gray code is a cyclic code. Gray
code cannot be used for arithmetic operation.

Application of Gray code

 Gray code is popularly used in the shaft position encoders.


 A shaft position encoder produces a code word which represents
the angular position of the shaft.

Binary Coded Decimal (BCD) code

In this code each decimal digit is represented by a 4-bit binary


number. BCD is a way to express each of the decimal digits with a binary
code. In the BCD, with four bits we can represent sixteen numbers (0000 to

/mmediza
1 | Number Systems and Data Representation
38
3
8

1111). But in BCD code only first ten of these are used (0000 to 1001). The
remaining six code combinations i.e. 1010 to 1111 are invalid in BCD.

Advantages of BCD Codes


 It is very similar to decimal system.
 We need to remember binary equivalent of decimal numbers 0 to
9 only.
Disadvantages of BCD Codes
 The addition and subtraction of BCD have different rules.
 The BCD arithmetic is little more complicated.
 BCD needs more number of bits than binary to represent the
decimal number. So BCD is less efficient than binary.

Alphanumeric codes

A binary digit or bit can represent only two symbols as it has only
two states '0' or '1'. But this is not enough for communication between two
computers because there we need many more symbols for communication.
These symbols are required to represent 26 alphabets with capital and small
letters, numbers from 0 to 9, punctuation marks and other symbols.
The alphanumeric codes are the codes that represent numbers and
alphabetic characters. Mostly such codes also represent other characters
such as symbol and various instructions necessary for conveying
information. An alphanumeric code should at least represent 10 digits and
26 letters of alphabet i.e. total 36 items. The following three alphanumeric
codes are very commonly used for the data representation.

 American Standard Code for Information Interchange (ASCII).


 Extended Binary Coded Decimal Interchange Code (EBCDIC).
 Five bit Baudot Code.

ASCII code is a 7-bit code whereas EBCDIC is an 8-bit code. ASCII


code is more commonly used worldwide while EBCDIC is used primarily
in large IBM computers.

/mmediza
1 | Number Systems and Data Representation
39
3
9

Error Codes

There are binary code techniques available to detect and correct data
during data transmission.

Error Code Description

Error Detection Error detection and correction


and Correction code techniques

👉 Exercise#1: Complete the table of numerical values below. Show your


solution in a separate sheet.

Decimal Binary Octal Hexadecimal


5910 (1) (2) (3)
(4) 011002 (5) (6)

(7) 1110112 (8) (9)

8510 (10) (11) (12)

(13) (14) 17738 (15)

13610 (16) (17) (18)

(19) (20) 65538 (21)


(22) (23) (24) 89AC16
(25) (26) (27) 19DF16

👉 Exercise#2: Evaluate the following binary numbers.


1.) 10011 2.) 11111 3.) 11010 4.) 111000
+ 01110 + 11111 - 10001 - 10001

5.) 10001 6.) 11010 7.) 10000 8.) 11000


÷ 00010 ÷ 00110 x 10001 x 10000

/mmediza
1 | Number Systems and Data Representation
40
4
0

👉 Exercise#3: Convert the following logic gate circuit into a Boolean


expression, writing Boolean sub-expressions next to each gate
output in the diagram and show the truth table for each:

A A
B B
1. 3.

A
A
B

C
B
2. 4.

1.3 References

Siyavula Technology. (2020). Number Systems.


https://intl.siyavula.com/read/it/grade-10-it/data-representation-storage-
and-social-implications/02-data-representation-storage-and-social-
implications?id=sec2-2.

Electronics Tutorial. (2020, February 26). Switching Theory of Boolean Logic.


Basic Electronics Tutorials. https://www.electronics-
tutorials.ws/boolean/switching-theory.html.

Tutotrial Point. (2020). Basics of Computers - Number System.


https://www.tutorialspoint.com/basics_of_computers/basics_of_computer
s_number_system.htm.

Jiang, Jie-Hong Roland. (2020). Switching Circuits and Logic Design.


http://cc.ee.ntu.edu.tw/~jhjiang/instruction/courses/fall13-ld/unit01.pdf

Note: Should you have questions about the topics discussed in this module, please
feel free to text or call me thru this cellphone number, 09672200502. I will
appreciate if you’ll ask questions for clarifications to have sufficient learning.

/mmediza

You might also like