13 Binary System

Download as pdf or txt
Download as pdf or txt
You are on page 1of 48

Binary system

Why Binary System?

• Computers are made of a series of switches


• Each switch has two states: ON or OFF
• Each state can be represented by a number – 1 for “ON” and 0 for
“OFF”
Number System Base Symbol

• Number systems include


Binary Base 2 B decimal, binary, octal and
hexadecimal
Octal Base 8 O • Each system have four
number base
Decimal Base 10 D

Hexadecimal Base 16 H
Significant Digits

Binary: 11101101

Most significant digit Least significant digit

Hexadecimal: 1D63A7A

Most significant digit Least significant digit


Binary Number System

• Also called the “Base 2 system”


• The binary number system is used to model the series of
electrical signals computers use to represent information
• 0 represents the no voltage or an off state
• 1 represents the presence of voltage or an
on state
Base 2 Base 10
Number Equivalent

000 0
001 1
Binary 010 2

Numbering 011 3

Scale
100 4
101 5
110 6
111 7
Decimal to Binary Conversion

• The easiest way to convert a decimal number to its binary


equivalent is to use the Division Algorithm
• This method repeatedly divides a decimal number by 2 and records
the quotient and remainder
• The remainder digits (a sequence of zeros and ones) form the binary
equivalent in least significant to most significant digit sequence
Division Algorithm
Convert 67 to its binary equivalent:
6710 = x2
Step 1: 67 / 2 = 33 R 1 Divide 67 by 2. Record quotient in next row

Step 2: 33 / 2 = 16 R 1 Again divide by 2; record quotient in next row

Step 3: 16 / 2 = 8 R 0 Repeat again

Step 4: 8 / 2 = 4 R 0 Repeat again

Step 5: 4 / 2 = 2 R 0 Repeat again

Step 6: 2 / 2 = 1 R 0 Repeat again

Step 7: 1 / 2 = 0 R 1 STOP when quotient equals 0

1 0 0 0 0 1 12
Binary to Decimal Conversion

• The easiest method for converting a binary number to its decimal


equivalent is to use the Multiplication Algorithm
• Multiply the binary digits by increasing powers of two, starting from
the right
• Then, to find the decimal number equivalent, sum those products
Multiplication Algorithm

Convert (10101101)2 to its decimal equivalent:

Binary 1 0 1 0 1 1 0 1
x x x x x x x x
Positional Values 27 26 25 24 23 22 21 20

Products 128 + 32 + 8 + 4 + 1

17310
Octal Number System

• Also known as the Base 8 System


• Uses digits 0 - 7
• Readily converts to binary
• Groups of three (binary) digits can be used to represent each octal
digit
• Also uses multiplication and division algorithms for conversion to and
from base 10
Hexadecimal Number System

• Base 16 system
• Uses digits 0-9 &
letters A,B,C,D,E,F
• Groups of four bits
represent each
base 16 digit
Decimal to Hexadecimal Conversion
Convert 83010 to its hexadecimal equivalent:

830 / 16 = 51 R14 = E in Hex


51 / 16 = 3 R3
3 / 16 = 0 R3

33E16
Hexadecimal to Decimal Conversion
Convert 3B4F16 to its decimal equivalent:

Hex Digits
3 B 4 F
x x x x
Positional Values
163 162 161 160
Products 12288 +2816 + 64 +15

15,18310
Binary to Hexadecimal Conversion
• The easiest method for converting binary to hexadecimal
is to use a substitution code
• Each hex number converts to 4 binary digits
binary Octal
By making pairs of 3 bits
binary Hexadecimal
By making pairs of 4 bits
Binary Addition
• Rule for binary addition is as follows:

0+0=0
0+1=1
1+0=1
1 + 1 = 0 plus a carry of 1 to next higher column
Binary Addition (Example 1)
Example
Add binary numbers 10011 and 1001 in both decimal and
binary form

Solution

Binary Decimal

carry 11 carry 1
10011 19
+1001 +9

11100 28
In this example, carry are generated for first and second columns
Binary Addition (Example 2)
Example

Add binary numbers 100111 and 11011 in both decimal


and binary form

Solution

Binary Decimal

carry 11111 carry 1


100111 39
+ 11011 +27

1000010 66
Binary Subtraction
• Rule for binary subtraction is as follows:

1–0=1
0-0=0
0 - 1 = 1 with a borrow from the next column 1 - 0 = 1
1-1=0
Binary Subtraction (Example)

Example

Subtract 011102 from 101012

Solution

10101
-01110

00111
1’s complement
2’s complement
Subtraction using 1’s complement

1. Take 1’s complement of the subtrahend


2. Add with minuend
3. If the result of addition has carry, then add it to the least significant
bit (LSB) of given result (+Ve)
4. If there is no carry, then take 1’s complement of the result which
will be negative
Subtraction using 1’s complement

1. Take 1’s complement of X= 110101


the subtrahend (Y) Y= 100101
2. Add with minuend (X)
3. If the result of addition
has carry, then add it to
the least significant bit
(LSB) of given result (+Ve)
4. If there is no carry, then
take 1’s complement of
the result which will be
negative
Subtraction using 1’s complement

1. Take 1’s complement of X= 101011


the subtrahend (Y) Y= 111001
2. Add with minuend (X)
3. If the result of addition
has carry, then add it to
the least significant bit
(LSB) of given result (+Ve)
4. If there is no carry, then
take 1’s complement of
the result which will be
negative
Subtraction using 2’s complement

1. Take 2’s complement of X= 110101


the subtrahend (Y) Y= 100101
2. Add with minuend (X)
3. If the result of addition
has carry, then dropped it
and result is (+Ve)
4. If there is no carry, then
take 2’s complement of
the result which will be
negative
Subtraction using 2’s complement

1. Take 2’s complement of X= 101011


the subtrahend (Y) Y= 111001
2. Add with minuend (X)
3. If the result of addition
has carry, then dropped it
and result is (+Ve)
4. If there is no carry, then
take 2’s complement of
the result which will be
negative
Binary Codes

• The digital data is represented, stored and transmitted as group


of binary bits, this group is called binary codes.
• The binary codes are represented by no. as well as alphanumeric
letters.
• Classification of binary codes:
• BCD (Binary coded Decimal)
• ASCII
• ASCII-8
• EBCDIC
• Gray code
• Excess-3 codes
BCD (Binary Coded Decimal)

• It is the simplest binary code to represent a decimal


number.
• In BCD, a decimal number is represented by four binary
bits
3➔ 0011
• If the decimal no. consist of two or more digits, each
decimal digit is individually represented by its 4 bit binary
equivalent
56➔ 0101 0110
BCD (Binary Coded Decimal)

DECIMAL BCD
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
ASCII (American Standard Code for Information
Interchange)
• It is used in small computers and peripheral, instruments
and communication devices
• It is a 7 bit code
• Upto 128 characters can be coded.
• Letter, digits, lowercase, uppercase, special symbols
included.
ASCII -8

• extended ASCII code


• A newer version of ASCII is known as ASCII-8
• It is an 8 bit code
• With 8 bits code capacity is extended to 256 characters.
Extended Binary Coded Decimal Interchange Code
(EBCDIC)

It is an 8-bit binary code for numeric and alphanumeric characters.

It was developed and used by IBM.

It is mainly used on IBM mainframe and IBM mid range computer operating
systems.

It is a coding representation in which symbols, letters and numbers (256) are


presented in binary language.
Gray code

It is a coded binary representation of a decimal digit which has a change in 1-bit position for
consecutive digits.

If there is any error in code, we can at least be assured that there will be only one bit position
change.

Gray codes are used in the general sequence of hardware-generated binary numbers.

These numbers cause errors when the transition from one number to its successive is done.

This code simply solves this problem by changing only one bit when the transition is between
numbers is done.
Binary to Gray conversion
1. Record the MSB (most significant bit) as it is.
2. Add the MSB to the next bit, Record the sum, and neglect the carry.
3. Repeat this process.

1011
Gray Code
Table
Decimal Digit BCD Code Excess-3 Code

Excess-3 Code 0 0000 0011

1 0001 0100

• It is a 4 bit code, same as BCD 2 0010 0101

• It can be of a decimal number 3 0011 0110

by simply adding 3 to each


decimal digit. 4 0100 0111

• And then we write the 4-bit 5 0101 1000

binary number for each digit of 6 0110 1001


the decimal number.
7 0111 1010

8 1000 1011

9 1001 1100
Fixed-Point Representation

• Signed No
• E.g. -9, +9
• Unsigned No.
• E.g. 9
Signed Number representation
• To represent a –ve no. a 1
1. Signed magnitude representation is placed before the no.
• 0→+
• 1→- • Ex.
2. Signed 1’s complement • -9 will be represented as
representation 1 1001
3. Signed 2’s complement
representation
Signed magnitude representation

• 0→+ve
• 1→-ve
• Most significant bit represent as a sign bit, of an integer & remaining
bits represent magnitude.
• Syntax: Sign bit Magnitude
(first bit) (binary bits)

• Ex: represent -7 with sign and magnitude


1 111

-7➔1111 +7➔0111
Complement form
Sign bit 1’s complement of no.

-7➔1000 +7➔0000

Sign bit 2’s complement of no.

-7➔1001 +7➔0001
Signed Number representation

• There are only one way to represent +ve no. but 3 ways to represent a –ve no.
1. Signed magnitude representation
11001
2. Signed 1’s complement representation
10110
3. Signed 2’s complement representation
10111

For ex. An 8 bit computer will represent -9 as:


7 bit for no. & 1 bit for sign 10001001, 11110110, 11010111
Que.

• Store -14 in an 8 bit using signed magnitude, 1’s and 2’s


complement.

You might also like