0% found this document useful (0 votes)
11 views23 pages

Ift211 Part2

The document discusses the representation of signed binary numbers, including sign-magnitude, 1's complement, and 2's complement forms, and their applications in arithmetic operations. It also covers binary codes such as Binary-Coded-Decimal (BCD), Gray code, Excess-3 code, and alphanumeric codes like ASCII and EBCDIC. Additionally, it introduces binary logic and basic logic gates, explaining their functions and relationships through truth tables.

Uploaded by

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

Ift211 Part2

The document discusses the representation of signed binary numbers, including sign-magnitude, 1's complement, and 2's complement forms, and their applications in arithmetic operations. It also covers binary codes such as Binary-Coded-Decimal (BCD), Gray code, Excess-3 code, and alphanumeric codes like ASCII and EBCDIC. Additionally, it introduces binary logic and basic logic gates, explaining their functions and relationships through truth tables.

Uploaded by

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

DEPARTMENT OF COMPUTER SCIENCE

Faculty of Computing
Federal University of Lafia
CENTRE FOR CONTINUING EDUCATION AND PROFESSIONAL
DEVELOPMENT (CCEPD)

Nasarawa State – Nigeria.

(2024/2025 Academic Session)


Representation of Signed Binary Numbers
Digital circuitry requires both positive and negative numbers. The Most
Significant Bit (MSB) of signed binary numbers is used to indicate the sign
of the numbers. Hence, it is also called as sign bit. The positive sign is
represented by placing ‘0’ in the sign bit.
Similarly, the negative sign is represented by placing ‘1’ in the sign bit.
If the signed binary number contains ‘N’ bits, then (N-1) bits only represent
the magnitude of the number since one bit (MSB) is reserved for
representing sign of the number.
There are three types of representations for signed binary numbers
• Sign-Magnitude form

• 1’s complement form


• 2’s complement form
Representation of a positive number in all these 3 forms is same. But, only
the representation of negative number will differ in each form.
Example
Consider the positive decimal number +108. The binary equivalent
of magnitude of this number is 1101100. These 7 bits represent the
magnitude of the number 108. Since it is positive number, consider the
sign bit as zero, which is placed on left most side of magnitude.
(+108)10 = (01101100)2

Therefore, the signed binary representation of positive decimal


number +108 is 𝟎𝟏𝟏𝟎𝟏𝟏𝟎𝟎. So, the same representation is valid in sign-
magnitude form, 1’s complement form and 2’s complement form for
positive decimal number +108.

Sign-Magnitude form
In sign-magnitude form, the MSB is used for representing sign of the
number and the remaining bits represent the magnitude of the
number. So, just include sign bit at the left most side of unsigned binary
number. This representation is similar to the signed decimal numbers
representation.
Example
Consider the negative decimal number -108. The magnitude of this
number is 108. We know the unsigned binary representation of 108 is
1101100. It is having 7 bits. All these bits represent the magnitude.
Since the given number is negative, consider the sign bit as one, which is
placed on left most side of magnitude.
(−108)10 = (11101100)2

Therefore, the sign-magnitude representation of -108 is 11101100.

1’s complement form


The 1’s complement of a number is obtained by complementing all
the bits of signed binary number. So, 1’s complement of positive
number gives a negative number. Similarly, 1’s complement of negative
number gives a positive number.
That means, if you perform two times 1’s complement of a binary number
including sign bit, then you will get the original signed binary number.

Example
Consider the negative decimal number -108. The magnitude of this
number is 108. We know the signed binary representation of 108 is 01101100.
It is having 8 bits. The MSB of this number is zero, which indicates
positive number. Complement of zero is one and vice-versa. So, replace
zeros by ones and ones by zeros in order to get the negative number.
(−108)10 = (10010011)2

Therefore, the 1’s complement of (108)10 is (10010011)2.

2’s complement form


The 2’s complement of a binary number is obtained by adding one to
the 1’s complement of signed binary number. So, 2’s complement of
positive number gives a negative number. Similarly, 2’s complement of
negative number gives a positive number.
That means, if you perform two times 2’s complement of a binary number
including sign bit, then you will get the original signed binary number.

Example
Consider the negative decimal number -108.

We know the 1’s complement of (108)10 is (10010011)2


2’s compliment of (108)10 = 1’s compliment of (108)10 + 1.

= 10010011 + 1
= 10010100
Therefore, the 2’s complement of (108)10 is (10010100)2.

In this chapter, let us discuss about the basic arithmetic operations,


which can be performed on any two signed binary numbers using 2’s
complement method. The basic arithmetic operations are addition
and subtraction.

Addition of two Signed Binary Numbers


Consider the two signed binary numbers A & B, which are represented
in 2’s complement form. We can perform the addition of these two
numbers, which is similar to the addition of two unsigned binary
numbers. But, if the resultant sum contains carry out from sign bit,
then discard (ignore) it in order to get the correct value.
If resultant sum is positive, you can find the magnitude of it directly. But,
if the resultant sum is negative, then take 2’s complement of it in order to
get the magnitude.
Example 1
Let us perform the addition of two decimal numbers +7 and +4 using 2’s
complement method.
The 2’s complement representations of +7 and +4 with 5 bits each are
shown below.

(+7)10 = (00111)2

(+4)10 = (00100)2

The addition of these two numbers is


(+7)10 + (+4)10 = (00111)2 + (00100)2

(+7)10 + (+4)10 = (01011)2.

The resultant sum contains 5 bits. So, there is no carry out from sign
bit. The sign bit ‘0’ indicates that the resultant sum is positive. So, the
magnitude of sum is 11 in decimal number system. Therefore, addition
of two positive numbers will give another positive number.
Example 2
Let us perform the addition of two decimal numbers -7 and -4 using 2’s
complement method.
The 2’s complement representation of -7 and -4 with 5 bits each are shown
below.

(−7)10 = (11001)2

(−4)10 = (11100)2

The addition of these two numbers is

(−7)10 + (−4)10 = (11001)2 + (11100)2

(−7)10 + (−4)10 = (110101)2.

The resultant sum contains 6 bits. In this case, carry is obtained from sign
bit. So, we can remove it
Resultant sum after removing carry is (−7)10 + (−4)10 = (10101)2.
The sign bit ‘1’ indicates that the resultant sum is negative. So, by
taking 2’s complement of it we will get the magnitude of resultant sum
as -11 in decimal number system. Therefore, addition of two negative
numbers will give another negative number.

Subtraction of two Signed Binary Numbers


Consider the two signed binary numbers A & B, which are represented
in 2’s complement form. We know that 2’s complement of positive
number gives a negative number. So, whenever we have to subtract a
number B from number A, then take 2’s complement of B and add it to
A. So, mathematically we can write it as
A - B = A + (2's complement of B)
Similarly, if we have to subtract the number A from number B, then take
2’s complement of A and add it to B. So, mathematically we can write
it as
B - A = B + (2's complement of A)

So, the subtraction of two signed binary numbers is similar to the


addition of two signed binary numbers. But, we have to take 2’s
complement of the number, which is supposed to be subtracted. This
is the advantage of 2’s complement technique. Follow, the same rules
of addition of two signed binary numbers.
Example 3
Let us perform the subtraction of two decimal numbers +7 and +4
using 2’s complement method. The subtraction of these two numbers
is
(+7)10 − (+4)10 = (+7)10 + (−4)10.

The 2’s complement representation of +7 and -4 with 5 bits each are


shown below.

(+7)10 = (00111)2

(+4)10 = (11100)2

(+7)10 + (+4)10 = (00111)2 + (11100)2 = (00011)2


Here, the carry obtained from sign bit. So, we can remove it. The resultant
sum after removing carry is

(+7)10 + (+4)10 = (00011)2


The sign bit ‘0’ indicates that the resultant sum is positive. So, the
magnitude of it is 3 in decimal number system. Therefore, subtraction of
two decimal numbers +7 and +4 is +3.
Example 4
Let us perform the subtraction of two decimal numbers +4 and +7
using 2’s complement method. The subtraction of these two numbers
is
(+4)10 − (+7)10 = (+4)10 + (−7)10.
The 2’s complement representation of +4 and -7 with 5 bits each are
shown below.

(+4)10 = (00100)2

(-7)10 = (11001)2

(+4)10 + (-7)10 = (00100)2 + (11001)2 = (11101)2


Here, carry is not obtained from sign bit. The sign bit ‘1’ indicates that
the resultant sum is negative. So, by taking 2’s complement of it we
will get the magnitude of resultant sum as 3 in decimal number system.
Therefore, subtraction of two decimal numbers +4 and +7 is -3.
In the coding, when numbers or letters are represented by a specific
group of symbols, it is said to be that number or letter is being encoded.
The group of symbols is called as code. The digital data is represented,
stored and transmitted as group of bits. This group of bits is also called
as binary code.

Binary Codes
Code is a system of rules to convert information- such as a letter, word,
sound, image, or gesture- into another form or representation,
sometimes shortened or secret, for use it to security reasons.
There are many types of codes: -

1) Binary-Coded-Decimal Code (BCD – 8421) (Weighted Code)


If each digit of a decimal number is represented by its binary equivalent,
the result is a code called binary-coded-decimal (hereafter abbreviated
BCD). Since a decimal digit can be represented from (0 – 9), four bits are
required to code each digit (the binary code for 9 is 1001).
Table below gives the four‐bit code for one decimal digit.

Decimal Symbol BCD Digit (8421)


0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001

To illustrate the BCD code, take a decimal number such as 874. Each
digit is changed to its binary equivalent as follows:

As another example, let us change 943 to its BCD-code representation:

Example: Convert 0110100000111001 (BCD) to its decimal equivalent.


Solution: Divide the BCD number into four-bit groups and convert each
to decimal.

2) Gray Code (non-weighted 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.
Example: Convert (101011)2 to Gray code.
Solution:

3) Excess-3 code (non-weighted 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: -
4) 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.

BINARY LOGIC
This binary logic system is one of a class of mathematical systems
generally called Boolean algebras (after the English mathematician
George Boole, who in 1854 published a book introducing the
mathematical theory of logic).
• Binary logic deals with binary variables (i.e. can have two values, “0”
and “1”) Binary variables can undergo three basic logical operators
AND, OR and NOT:
– AND is denoted by a dot (·)
– OR is denoted by a plus (+).
– NOT is denoted by an overbar (¯), a single quote mark (') after
the variable.

• AND. This operation is represented by a dot or by the absence of an


operator. For example, Z =X · Y or Z = XY is read “Z is equal to X AND
Y.” The logical operation AND is interpreted to mean that Z = 1 if and
only if X = 1 and Y = 1; otherwise Z = 0. (Remember that X, Y, and Z
are binary variables and can be equal to only 1 or 0.)
• OR. This operation is represented by a plus symbol. For example, Z
=X = Y is read “Z is equal to X OR Y,” meaning that Z = 1 if X = 1 or if
Y = 1, or if both X = l and Y = 1. Z = 0 if and only if X = 0 and Y = 0.
• NOT. This operation is represented by a bar over the variable. For
example, Z =X’ is read “Z is equal to NOT X,” meaning that Z is what
X is not. In other words, if X = 1, then Z = 0; but if X = 0, then Z = 1.
The NOT operation is also referred to as the complement operation,
since it changes a 1 to 0 and a 0 to 1.

BINARY LOGIC GATES


The basic building blocks of a computer are called logical gates. Gates
are basic circuits that have at least one (and usually more) input and
exactly one output. Input and output values are the logical values true
and false. In computer architecture it is common to use 0 for false and 1
for true. Gates have no memory. The value of the output depends only on
the current value of the inputs. A useful way of describing the relationship
between the inputs of gates and their output is the truth table. In a truth
table, the value of each output is tabulated for every possible combination
of the input values. We usually consider three basic kinds of gates, AND-
gates, OR-gates, and NOT-gates (or Inverters).

❖ BASIC GATES
1) AND Gate: -
The AND operation is represented by a dot (.) or by the absence of an
operator.
E.g. A.B=F AB=F are all read as A AND B=F. the logical operation AND
is interpreted to mean that F=1 if A=1 and B=1 otherwise F=0

2) OR Gate: -

The OR operation is represented by a (+) sign for example, A+B=F is


interpreted as A OR B=F meaning that F=1 if A=1 or B=1 or if both A=1
and B=1. If both A and B are 0, then F=0.

3) NOT Gate or INVERTER: -

The inverter is a little different from AND and OR gates in that it


always has exactly one input as well as one output. Whatever logical state
is applied to the input, the opposite state will appear at the output. This
operation is represented by a bar or a prime. For example, A′=A=B is
interpreted as NOT A =B.
❖ Combined gates
Sometimes, it is practical to combine functions of the basic gates into
more complex gates, for instance in order to save space in circuit
diagrams. In this section, we show some such combined gates together
with their truth tables.
1) NAND Gate: -
The NAND-gate is an AND-gate with an inverter on the output. This
operation is

Represented by F=A.B. So instead of drawing several gates like this:

2) NOR Gate: -
The NOR-gate is an OR-gate with an inverter on the output. This
operation is

Represented by F=A+B. So instead of drawing several gates like this:


3) Exclusive OR Gate (Ex-OR/ XOR): -
The Exclusive-OR-Gate is similar to an OR-gate. It can have an arbitrary
number of inputs, and its output value is 1 if exactly one input is 1 (and
thus the others 0).

4) Exclusive NOR Gate (Ex-NOR/ XNOR): -


The Exclusive-NOR-Gate is similar to an NOR-gate. It can have an
arbitrary number of inputs, and its output value is 1 if the two inputs are
of the same values (1 and 1
Boolean algebra
Boolean algebra is an algebra, which deals with binary numbers & binary
variables. Hence, it is also called as Binary Algebra or logical Algebra. A
mathematician, named George Boole had developed this algebra in 1854.
The variables used in this algebra are also called as Boolean variables.

Boolean algebra is set of rules, used to simplify the given logic expression
without changing its functionality.

❖ Postulates and Basic Laws of Boolean algebra


In this section, let us discuss about the Boolean postulates and basic laws
that are used in Boolean algebra. These are useful in minimizing Boolean
functions.

Boolean Postulates
Consider the binary numbers 0 and 1, Boolean variable (x) and its
complement
(x’). Either the Boolean variable or complement of it is known as literal.
The four possible logical OR and logical AND operations among these
literals and binary numbers are shown below.
These are the simple Boolean postulates. We can verify these postulates
easily, by substituting the Boolean variable with ‘0’ or ‘1’.
Note− The complement of complement of any Boolean variable is equal
to the variable itself. i.e., (x’)’=x.

Basic Laws of Boolean algebra


Following are the three basic laws of Boolean algebra.
• Commutative law
• Associative law
• Distributive law

Commutative Law
If any logical operation of two Boolean variables give the same result
irrespective of the order of those two variables, then that logical operation
is said to be Commutative. The logical OR & logical AND operations of
two Boolean variables x & y are shown below
x+y=y+x
x.y=y.x
Associative Law
If a logical operation of any two Boolean variables is performed first and
then the same operation is performed with the remaining variable gives
the same result, then that logical operation is said to be Associative. The
logical OR & logical AND operations of three Boolean variables x, y & z
are shown below.
x + (y + z) = (x + y) + z
x . (y . z) = (x . y). z
Distributive Law
If any logical operation can be distributed to all the terms present in the
Boolean function, then that logical operation is said to be Distributive.
The distribution of logical OR & logical AND operations of three Boolean
variables x, y & z are shown below.
x .(y + z)

=x.y+

x.zx+
(y.z) =

(x+y).(x+

z)

These are the Basic laws of Boolean algebra. We can verify these laws
easily, by substituting the Boolean variables with ‘0’ or ‘1’.

❖ Theorems of Boolean algebra

The following two theorems are used in Boolean algebra.


• Duality theorem
• DeMorgan’s theorem

Duality Theorem
This theorem states that the dual of the Boolean function is obtained by
interchanging the logical AND operator with logical OR operator and
zeros with ones. For every Boolean function, there will be a
corresponding Dual function.
Let us make the Boolean equations (relations) that we discussed in the
section of Boolean postulates and basic laws into two groups. The
following table shows these two groups.

DeMorgan’s Theorem
This theorem is useful in finding the complement of Boolean
function. It states that the complement of logical OR of at least two
Boolean variables is equal to the logical AND of each complemented
variable.
DeMorgan’s theorem with 2 Boolean variables x and y can be represented
as
(x + y)’ = x’. y’
The dual of the above Boolean function is
(x . y)’ = x’ + y’
Therefore, the complement of logical AND of two Boolean variables is
equal to the logical OR of each complemented variable. Similarly, we can
apply DeMorgan’s theorem for more than 2 Boolean variables also.
Examples: - Find the complement and dual of the following functions.

Boolean Function
Boolean algebra is an algebra that deals with binary variables and logic
operations.
A Boolean function described by an algebraic expression consists of
binary variables, the constants 0 and 1, and the logic operation symbols.
For a given value of the binary variables, the function can be
equal to either 1 or 0. F(vars) = expression

Set of binary Variables Operators (+, •, ‘)


Constants (0, 1)
Groupings (parenthesis)
Variables
Consider an example for
the Boolean
function F1 = x
+ y’z

Simplification of Boolean Functions


Till now, we discussed the postulates, basic laws and theorems of
Boolean algebra. Now, let us simplify some Boolean functions.
Examples: simplify the following Boolean functions.
Complement of a Function
• The complement of a function is derived by interchanging (• and
+), and (1 and 0), and complementing each variable.
• Otherwise, interchange 1s to 0s in the truth table column
showing F.
• The complement of a function IS NOT THE SAME as the dual of
a function.
Example
• Find G(x,y,z), the complement of F(x,y,z) = xy’z’ + x’yz
Ans: G = F’ = (xy’z’ + x’yz)’
= (xy’z’)’ • (x’yz)’ DeMorgan
= (x’+y+z) • (x+y’+z’) DeMorgan again
Note: The complement of a function can also be derived by
finding the function’s dual, and then complementing all of the
literals
DEFINITIONS
Literal: A variable or its complement
Product term: literals connected by •
Sum term: literals connected by +
Minterm: a product term in which all the variables appear exactly once,
either complemented or uncomplemented.
Maxterm: a sum term in which all the variables appear exactly once,
either complemented or uncomplemented.
Canonical form: Boolean functions expressed as a sum of Minterms or
product of Maxterms are said to be in canonical form.

You might also like