Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

FAC1002 - Binary Number System

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

CONTENTS

1> NUMBER SYSTEMS

2> DECIMAL SYSTEM

3> BINARY SYSTEM

4> BINARY-DECIMAL INTERCONVERSIONS


DECIMAL SYSTEM

INTRODUCTION
Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, Base, b = 10
Representation, {10n}
Notation : 72710 or 727

Example 1 (An integer)


737 = (7 x 102) + (3 x 101) + (7 x 100)
= 700 + 30 + 7

Example 2 (A real number / floating-point)


737.747 = (7 x 102) + (3 x 101) + (7 x 100) + (7 x 10-1)
+ (3 x 10-2) + (7 x 10-3)
= 700 + 30 + 7 + 0.7 + 0.04 + 0.007
ARITHMETIC OF DECIMAL SYSTEM
ADDITION
Example 3 737.777
+ 330.747
1068.524
SUBSTRACTION 767.340
Example 4 380.757
- 386.583

MULTIPLICATION 4.166
Example 5 0.19
x 0.79154

DIVISION
Example 6 41.66 416.6 4166
   ...  0.064379539
647.1 6471 64710
BINARY SYSTEM

Electronic components of a computer are bistable in nature:


For example: yes/no, on/off.
These two possibles states are usually denoted by 0 and 1.
-- symbols for the digits of the binary number system.

In magnetic storage devices (Hard Rigid Disk, Floppy, Zip, Tape, etc.) magnetized
: a magnetized area stands for 1, and the absence of magnetization means 0.

Flip-flops-electronic devices that can only carry two distinct voltages at their
outputs and that can be switched from one state to the other state by an impulse-
can also be used to represent binary numbers;
• An individual unit of information is usually
represented in the computer by a sequence of these
binary digits (called bits ) .
 bits (Binary Digits)
 The smallest unit of data a computer can process

• Many computers use the binary number system not


only to represent quantities but to perform
calculations using binary arithmetic

Bytes-An 8-Bit grouped together


(for ASCII & EBCDIC schemes)
A 16-Bit grouped together
(for Unicode scheme)

Unit of byte
 prefix-B. Examples (kB = 103 Bytes,
MB for 106 Bytes, GB for 109 Bytes,
TB for 1012 Bytes, PB 1015 Bytes)
 CODING SCHEMES

1. ASCII (American Standard Code for Information Interchange)


~ Normally used in PC and Midrange Server
2. EBCDIC (Extended Binary Coded Decimal Interchange Code)
~ Mainframe, Supercomputer
3. Unicode
~ To support language characters other than English &
European Western languages.
~ More to expand in future use (6000 codes reserved
for private and 30000 for general reserve)
Fig 3-12 Computer Circuit Data Representation by Bit (Binary Digit)

Fig 3-13 Byte


Fig 3-14 Sample of ASCII and EBCDIC coding scheme
BINARY SYSTEM

INTRODUCTION
Set = {0, 1}, Base, b = 2
Representation, {2n} i.e. { …, 2-2, 2-1, 20, 21, 22,… }
Notation : 1001012

BINARY TO DECIMAL SYSTEM CONVERSION

Example 7 (An integer)


110012 = (1 x 24) + (1 x 23) + (0 x 22) + (0 x 21) + (1 x 20)
= 16 + 8 + 0 + 0 + 1
= 2510

Example 8 (A real number / floating-point)


101.0112 = (1 x 22) + (0 x 21) + (1 x 20) + (0 x 2-1) + (1 x 2-2) + (1 x 2-3)
= 4 + 0 + 1 + 0 + 0.25 + 0.125
= 5.37510
Numbers and Their ‘Bases’ (3)

Part b. of this diagram has 10112 . That is equal to 11 in Base 10.


DT211-1 Computer 10
Technology
Algorithm for Finding the Binary
Representation of a Positive Integer

• Step 1. Divide the value by two and record the


remainder.

• Step 2. As long as the quotient obtained is not zero,


continue to divide the newest quotient by two and record the
remainder.

• Step 3. Now that the quotient of zero has been


obtained, the Binary representation of the original value
consists of the remainders listed from right to left in the
order they were recorded.
CONVERTING A DECIMAL NUMBER TO BINARY EQUIVALENT
1.DECIMAL TO BINARY SYSTEM CONVERSION

Example
(Converting an integer, NI = 737 to binary equivalent)

2 737
2 368 1
2 184 0
2 0
92
2 0
46
0
2 23
1
2 11
1
2 5 1
2 2 0 Remainders (Direction of reading)
2 1 1
0

Therefore, NI = 73710 is equivalent to NI = 10111000012


CONVERTING A FLOATING-POINT NUMBER TO BINARY EQUIVALENT

Example
(Converting a floating-point, NF = 0.84375 to binary equivalent)

0.84375
2 Keep 1 and just multiply
1 .6875 0.6875 x 2 = 1.375
2 Keep 1 and just multiply
1 .375 0.375 x 2 = 0. 75
2 Keep 0 and just multiply
0 .75 0. 75 x 2 =1.5
2 Keep 1 and just multiply
1 .5 0. 5 x 2 =1.0
2 Cannot multiply anymore because
1 .0 what left is just zero so you can stop now.
Integral Parts
(Direction of Therefore, NF = 0.8437510 is equivalent to
reading) NF = 0.110112
Example

(Converting a floating-point, NF = 737.84375 to binary equivalent)

Since NF = 737.84375 = 73710 + 0.8437510 in decimal system,

Therefore in binary equivalent,

NF = 10111000012 + 0.110112 = 1011100001.110112


Example 11
(Converting a floating-point, NF = 0.3 to binary equivalent)
0.3
Integral Parts 2 RESULT : Example 11 shows that binary equivalent
(Direction of reading)  0 .6 of a terminating decimal fraction, i.e. NF = 0.3 does
2 not always terminate, but we obtain repeating pattern
1 .2 of alternate pattern of integral part.
2
 0 .4
2
 0 .8
2
1 .6
2
1 .2
2
 0 .4 Thus for NF = 0.3, we shall only write the binary
2 equivalent as NF = 0.0 1001 1001 1001…… 2
 0.8
2 Or 0.01001 2
1.6
2 Some corrections if you watch the video example 1:
1.2 Converting a floating point number to binary
2 equaivalent...in the video i said the answer is
 0.4 = 0.0 10011 2 It should be 0.010012
.
.
Binary Arithmetic
Binary arithmetic is used in digital systems to represent
numbers (decimal and floating-point numbers) which are
stored in binary format in most computer systems.

All arithmetic operations ( addition, subtraction,


multiplication, division) are done in binary and this is vital
to understand the binary number representation to figure
out binary arithmetic in digital computers.

In most ALU (arithmetic logic unit) hardware, the operated


numbers are stored in a fixed number of bits, a typical
value between 6 and 16 decimal digits. Therefore, there is a
precision limit or precision error performing binary
arithmetic on computers. This binary arithmetic is called
fixed-precision arithmetic.
• A binary addition example for single binary digits:

02 12 02 12
+02 +02 + 12 + 12
02 12 12 1 02

17
Normal procedure for addition and subtraction in binary numbers

1010112 110112
+ 10002 + 10102
1100112 1001012

1010112 1
1000 2 1010002
- 10002 - 1002 - 10112
1000112 1002 111012
From the right hand side
Step 1: 0-0 = 0
Step 2: 0-0 = 0
Step 3: Borrow to make 10-1=1
Your final answer 1002
Multiplication and Division in binary numbers

Example:
BASE

1 0 1 2

x 1 1 2

1 0 1 2

1 0 1 2

1 1 1 1 2
Example:

BASE
1 1 1 2
x 1 1 2
1 1 1 2
+ 1 1 1 2
1 0 1 0 1 2

1+1=2 ( in decimal)
but in binary its 102
That’s why 1 is
carry forward to the
other side then...

1+1+1=3 ( in
decimal)
but in binary its 112
That’s why 1 is
carry forward to the
other side.
Multiplication and Division in binary numbers
Example:
11112 ÷ 1012 = 112

1 1
101 1 1 1 1
-1 0 1
1 0 1
-1 0 1
- - -
Example:

1002 ÷ 112 = 1.01012

1 1. 0 1 0 1
11 1 0 0 11 1 0 0. 0 0 0 0
- 1 1 - 1 1
1 0
1
0
1 0 0
1 1
1 0
- 0
1 0 0
- 1 1
1
Binary Mathematics
• The fact that data is represented in binary allows a computer
to convert numbers, as data elements, by the mathematical
operations of programmed addition, subtraction,
multiplication and division.

• For binary machines (computers) it is usually impossible to do


subtraction and division.

• It is more feasible for binary numbers to be added to each


other to allow any required conversion of a number – even
when effecting a subtraction, multiplication or division. (This
seems odd, but it is how ‘relay devices’ do (and must) work.

23
Binary Mathematics
• For that reason the mathematics of binary are based on
increments and decrements.

For example, 2 x 3 would be processed as 00000010


incremented by itself three times. That would be:
00000010
+ 00000010
+ 00000010
= 00000110 (000001102 = 610)

24
Binary Mathematics
• *** Note ***
Decrements in binary mathematics are achieved, not
by simple subtraction, but by the addition of a
negative number!

25
Several schemes representing signed integer in a computer.
Signed number representations are required to encode
negative numbers in binary number systems.

1. sign-magnitude
2. 1’s complement
3. 2’s complement

All these methods have one common feature:


* the leftmost bit is reserved to represent the sign of the
integer
* 0 indicates positive number while 1 indicates negative number
1. Sign magnitude:

The sign and magnitude (absolute value) of the integer are represented
 separately
A negative integer, for example is represented by “1” in the leftmost bit
and the absolute value in the remaining bits.

Example: for 8-bit machine, the integers 30 and -30

27 26 25 24 23 22 21 20
30: 0 0 0 1 1 1 1 0

-30: 1 0 0 1 1 1 1 0

It’s a poor choice for integer representation in modern day


computer systems
2. 1’s Complement

Left-most bit is initially set to zero.


Absolute value of number (binary format) occupies the
remaining bit places
For a negative number ALL the bits are then complemented
(i.e. reversed). Note that this will make the sign bit “1” as it
should be.

Example :The 1’s complement representation of 30 and -30:


27 26 25 24 23 22 21 20
30 : 0 0 0 1 1 1 1 0

-30 : 1 1 1 0 0 0 0 1

Prob: -0 and +0 are represented differently even though they are the
same algebraically
Addition in 1’s complement

Rule: Carry over of leftmost digit during addition is added back to the bit
string

Example: -1+5 using 4-bits representation

23 22 21 20
+1: 0 0 0 1
1

-1 : 1 1 1 02
+5: 0 1 0 12 +
10 0 1 12 0 0 1 12
12 +
0 1 0 02 +4

Exercise: Try 6 – 3=? using 6 bits representation


3. 2’s complement

Positive numbers are treated like one’s complement


Negative numbers representation obtained by adding 1 to 1’s
complement representation

i. Start with the absolute value in binary


ii. Then complement all the bits
iii. Now add 1 to the result

The 8-bit 2’s complement of representation -30 is

27 26 25 2 4 23 22 21 20
i. 30 : 0 0 0 1 1 1 1 0

ii. 1 1 1 0 0 0 0 1
iii. 1+
-30: 1 1 1 0 0 0 1 02
Addition in 2’s Complement

Adding two 2’s complement numbers involve adding the bit strings as an unsigned
number and ignoring the carry out of the leftmost bit if there is one

Example:

Add 92 and -45 in 2’s complement using 8-bits

92= 0 1 0 1 1 1 0 0
-45 = ??

Firstly 45 = 00101101
Complemented = 11010010
Add 1 = 11010011
Therefore -45 = 11010011

92 : 0 1 0 1 1 1 0 0
-45 : + 1 1 0 1 0 0 1 1 Drop the leftmost
1 001011112 carry bit: =001011112

You might also like