0% found this document useful (0 votes)
1 views

Binary_Code-1

Binary code guide
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Binary_Code-1

Binary code guide
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

Computer Organization

Binary Representation
The Binary Code
At the most fundamental level, computers
only understand zeros and ones.
A single 0 or 1 is called a
bit, which is a contraction of binary digit.
So how does a computer go from zeros
and ones to colourful graphical interfaces
with buttons and web browsers?
Number Systems
Number system
Is a system of writing used to express numbers in different
forms.
Number
A mathematical value used to count, measure, and perform
various arithmetic calculations.

Based on their properties, numbers are classified into


different types, such as natural numbers, whole numbers,
fractions, rational and irrational numbers, and so on.
In a similar way, we have different kinds of number
systems, such as a binary number system, an octal number
system, a decimal number system, and a hexadecimal
number system.
Decimal Number System Binary Number System
The number system that represents a A number system that expresses a nu
number in terms of 0 to 9 digits (i.e., 0, mber in terms of 0 and 1 digits (i.e.,

Decimal VS
1, 2, 3, 4, 5, 6, 7, 8, and 9). 0 and 1).

Numbers are expressed in terms of Numbers are in terms of powers of 2.

Binary
powers of 10.
In binary, base 2, there are only two
The positions of successive digits to digits (0 and 1), and each place is
the left of the decimal point represent worth two times the place to its right
units, tens, hundreds, thousands, and (1, 2, 4, 8, 16, 32, 64, 128, 356).
so on.
Number
Example: (123)10 in powers of 10 is
expressed as:
Example: (1011)2 is expressed in power
s of 2 as: Systems
(1 × 102) + (2 × 101) + (3 × 100) = (1 × 23) + (0 × 22) + (1 × 21) + (1 × 20) =

1 ×100 + 2 × 10 + 3 × 1 = (1 × 8) + (0 × 4) + (1 × 2) + (1 × 1) =

100 + 20 + 3 = 123 8 + 0 + 2 + 1 = 11
Decimal
number
Binary
number
Binary to
1 01 Decimal Conversion
2 10 We can convert a number from any number system into any of
the other three number systems.
3 11
To convert a binary number into a decimal number, multiply
4 100 each digit of the binary number by the power of 2.
5 101 If B = an-1…a3a2a1a0 is a binary number that has n digits, then
the respective decimal number will be
6 110

7 111
D = (a n-1 × 2n-1) +…+(a3 × 23 ) + (a 2 × 22 ) + (a 1 × 21 ) + (a 0 × 20 )
8 1000

9 1001

10 1010
Conversion of Binary to Decimal
Example 1: Convert (11001)2 to a decimal number.

Example 2: Convert (10010)2 to a decimal number.


Conversion of Binary to Decimal
Example: Convert (11001)2 to a decimal number.
The given binary number is (11001)2.
(11001)2 = (1 × 24) + (1 × 23) + (0 × 22) + (0 × 21) + (1 × 20)
= 16 + 8 + 0 + 0 + 1 = (25)10
Therefore, the binary number (11001)2 is expressed as (25)10.
Decimal number Binary number
Decimal to Binary
Conversion
1 01

2 10

3 11 To convert a decimal number into a binary


number, divide the given number by 2
4 100 continuously till we get the quotient as 1. Note
5 101
that we have to write the numbers from
downwards to upwards.
6 110
Convert (31)10 into a binary number
2 31
7 111
2 15 1
8 1000 2 7 1
9 1001 2 3 1

10 1010 2 1 1

Therefore, (31)10 is expressed as (11111)2


Conversion of Binary to Decimal
Example: Convert (46)10 into a binary number.

Example: Convert (124)10 into a binary number.


Conversion of Binary to Decimal
Example: Convert (46)10 into a binary number.
2 46

2 23 0

2 11 1

2 5 1

2 2 1

2 1 0

Therefore, (46)10 is expressed as (101110)2.


Bits
and
Bytes
Bits, bytes and
words
The binary system have names for
specific numbers of digits like.
A single digit in binary is called a
bit. A bit is a value that can either be 0
or 1.
In order to make anything meaningful
out of bits, they must be grouped into
strings. A string of bits is called a
binary string.
And 8 digits string is called a byte.
Binary also has a name for 16 digits.
That’s a word. And for 32 digits. That’s
a double word.
Bits, bytes and words
Because each position in a string can be occupied by one of two bits, there
are a total of 2n binary strings of length n.
Name Bits Total Number of Strings Combimations

Bit 1 21 = 2 0, 1

2 22 =4 00, 01, 10, 11

3 23 = 8 000, 001, 010, 011, 100, 101, 110, 111

Byte 8 28 = 256 0000, 0001, 0010, 0100, 1000, 0011, 0101, 1001,...

Word 16 216 = 65,536 0000000000000001, 0000000000000010, 0000...

Doubleword 32 232 = 4 billlion 00000000000000000000000000000001, 000000...


00000000000000000000000000000000000000000000
264 =18 billion
Quadword 64 000000000000000001,
billion
0000000000000000000000000...
Data
Representation
A binary string means nothing
unless it is placed in some context
. It may represent various things, d
epending upon how it is being use
d at the time.
Computers can convert
information, such as text,
numbers, photos, or music, into
digital data that can be
manipulated by electronic
devices.
Integers
If we use one 8 bits to represent an integer numbers,
means that there can be 28 = 256 different
representations. This will allow us to represent all
positive integes from 0 to 255.
000000012 = 110
000001012 = 510
000110012 = 2510
111111112 = 25510
Integers
However we may wish to represent both positive and
negative numbers using the "sign-and-magnitude
number representation". This method represent the
sign by allocating the left-most bit as a sign bit. If it is a
0 is a positive number and a 1 a negative number
000000012 = 110
100000012 = -110
011111112 = 12710
111111112 = -12710
Characters
ASCII (American Standard Code for Information
Interchange) is a character-encoding scheme
originally based in the English alphabet.
A number is assigned to each letter from 0 to 127.
Decimal Binary Value Decimal Binary Value Decimal Binary Value

065 0100 0001 A 071 0100 0111 G 077 0100 1101 M

066 0100 0010 B 072 0100 1000 H 078 0100 1110 N

067 0100 0011 C 073 0100 1001 I 079 0100 1111 O

068 0100 0100 D 074 0100 1010 J 080 0101 0000 P

069 0100 0101 E 075 0100 1011 K 081 0101 0001 Q

070 0100 0110 F 076 0100 1100 L 082 0101 0010 R


Characters
Write a short message in ASCII. Exchange messages
with a partner and decode each other's message.
Images
An image is divided into pixels
(Short for Picture Element), each
pixel represents the smallest single
point on the screen.
A pixel can only be one colour at a
time. Each pixel is represented by a
number of bits and programs can
specify where each pixel is placed
on the screen and what colour it is
going to be.
The more bits that are used to
store each pixel, the more colors
are potentially available. VDUs
display output using millions of
pixels.
Images: Bitmap
The image represented called a Bitmap. This
example is a 1-bit image that shows how
pixels are made up of binary code.
The digit 0 is used for Black and the digit 1 is
used for White.
In reality, images are far more complexed
than the image shown, with color
depth and image resolution having a big
impact on the quality and file size of an
image.
Colors: Color Depth
The number of bits per pixel is referred to as the Color
Depth. It is important for the quality of the colors in an
image.
If 1-bit is used to encode each pixel, then only two
colors can be used (21). As we mentioned before,
the 0 represents black and the 1 represents white.
To be able to represent more than two colors in an
image, each pixel requires more bits. To work out the
minimum required colour depth from the number of
colours in the image, convert the number of colours to
a power of 2. For Example:
A 1-bit image can display 21, or 2 colors.
A 2-bit image can display 22, or 4 colors.
A 4-bit image can display 24, or 16 colors.
A 6-bit image can display 26, or 64 colors.
A 8-bit image can display 28, or 256 colors.
A 16-bit image can display 216, or 65,536 colous.
If the colour depth is increased, more bits are used to
represent each pixel, and the overall size of the file will
increase.The following image demonstrates how the
quality of an image changes depending on the number
of bits used
Colors: Resolution
Resolution is the number of pixels per inch – dpi- that
make up an image.
The greater the number of pixels per inch —>
the sharper the image will be, the greater
the quality and the larger the files size of the image.
Pixel density is measured in pixels per inch (PPI) and is
used to describe the resolution of a computer screen,
camera or scanner.
An image on the Internet is typically 72PPI, which is a
low resolution. If you try to enlarge the image on the
screen, the image will become pixelated and blurry.
See example below showing how an image becomes
blurred if you increase its size on the screen:
Boolean Arithmetic
Addition
The first three sums make perfect sense to anyone
familiar with elementary addition.
The last sum, though, is quite possibly responsible
for more confusion than any other single statement
in digital electronics, because it seems to run
contrary to the basic principles of mathematics.
Mutiplication
Multiplication is valid in Boolean algebra, and
thankfully it is the same as in real-number algebra:
anything multiplied by 0 is 0, and anything multiplied
by 1 remains unchanged:
Simple logic gates
Boolean Operators
Boolean
Operators
Computer systems are made up
of electricla circuits and use the
binary system to represent and
store data. In order to do so,
electrical circuits have been
designed to recieve one or more
binary numbers as their inputs
and produce a single output.
This circuits are governed by the
logic of Boolean logic.
There are six Boolean operators a
vailable: AND, OR, NOT, NAND,
NOR and XOR.
AND Gate
The & operator computes the logical AND of its operands. The result of a & b is true if
both a and b evaluate to true. Otherwise, the result is false.

Logic diagram a b ab
0 0 0

0 1 0

Boolean expression 1 0 0
Y=A·B
1 1 1
OR Gate
The OR logic operation returns true if either of its inputs are true. If all inputs are
false, the output is also false.

Logic diagram a b a+b


0 0 0

0 1 1

Boolean expression 1 0 1
Y=A+B
1 1 1
NOT Gate
NOT gate is also known as Inverter. It has one input A and one output Y. The Logic
NOT Function output is true when its single input is false, and false when its single
input is true.
Logic diagram a Y
0 1

1 0
Boolean expression
A=
Logic NOT Function Equivalents
Logic NOT gates or “Inverters” as they are more commonly called, can be connected
with standard AND and OR gates to produce NAND and NOR gates respectively.
NAND NOR
Logic diagram

Boolean expression Boolean expression


a b ab a b a+b
Y=A·B 0 0 1 Y=A+B 0 0 1
0 1 1 0 1 0
1 0 1 1 0 0
1 1 0 1 1 0
Practice
Convert the following logic gate circuit into a Boolean expression, writing Boolean sub-expressions next to each gate
output in the diagram:

a) b)
Practice
Draw a logic gate circuit for this function.

a) b)
Practice
Complete the truth tables for these two Boolean expressions:

a) b)
Introduction of K-Map
(Karnaugh Map)
In many digital circuits and practical problems we
need to find expression with minimum variables.
We can minimize Boolean expressions of 3, 4
variables very easily using K-map without using any
Boolean algebra theorems.
K-map is table like representation but it gives more
information than TRUTH TABLE.
We fill grid of K-map with 0’s and 1’s then solve it
by making groups.
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor
or a Motion Detector.
STEP 1: Identify the Inputs and Outputs
INPUTS OUTPUTS
Burglar alarm: Alarm:
1 – Alarm On 1 – On
0 – Alarm Off 0 – Off
Window Sensor:
0– Closed
1 – Open
Motion Detector:
1 – Motion
0 – No Motion
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor
or a Motion Detector.
STEP 2: Select an appropriate Truth Table
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor
or a Motion Detector.
STEP 3: Fill in the Truth Table

B W M A INPUTS OUTPUTS
0 0 0 Burglar alarm (B) Alarm (A)

0 0 1 1 – Alarm On 1 – On
0 – Alarm Off 0 – Off
0 1 0
Window Sensor (W)
0 1 1
0 – Closed
1 0 0
1 – Open
1 0 1
Motion Detector (M)
1 1 0
1 – Motion
1 1 1 0 – No Motion
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Identify the inputs that cause the output to be 1.

B W M A Combine min-terms to form the equation:


0 0 0 0
A = __ __ __ + __ __ __ + __ __ __
0 0 1 0
0 1 0 0 A=BWM+BWM+BWM

0 1 1 0
1 0 0 0
1 0 1 1
1 1 0 1
1 1 1 1
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Solutions can be simplified using Karnaugh Mapping.

A=BWM+BWM+BWM

WM 00 01 11 10
B
0 0 0 0 0

1 0 1 1 1
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Solutions can be simplified using Karnaugh Mapping.

A = BWM + BWM + BWM

WM 00 01 11 10
B
0 0 0 1 0

1 1 1 1 0
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Solutions can be simplified using Karnaugh Mapping.

A = BWM + BWM + BWM

WM 00 01 11 10
B
0 0 0 1 0

1 1 1 1 0

F 1 = BWM + BWM = BW (M + M) = BW

1
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Solutions can be simplified using Karnaugh Mapping.

A = BWM + BWM + BWM

WM 00 01 11 10
B
0 0 0 1 0

1 1 1 1 0

F 1 = BWM + BWM = BW (M + M) = BW
1
F 1 = BWM + BWM = WM (B + B) = WM
1
Example: Burglar Alarm
Consider the design of a Burglar Alarm for a house. This alarm will be
activated if an unauthorized person is detected by a Window Sensor or a
Motion Detector.
STEP 4: Solutions can be simplified using Karnaugh Mapping.

A = BWM + BWM + BWM

WM 00 01 11 10
B
0 0 0 1 0

1 1 1 1 0

F 1 = BWM + BWM = BW (M + M) = BW
1
F 1 = BWM + BWM = WM (B + B) = WM
1
A = WM + BW = W (B +MB)
Car Logic Circuit
An automotive engineer wants to design a logic circuit that
prohibits the engine in a car from being started unless the driver
is pressing the clutch pedal while turning the ignition switch to
the “start” position. The purpose of this feature will be to prevent
the car from moving forward while being started if ever the
transmission is accidentally left in gear.
Suppose we designate the status of the ignition switch “start”
position with the Boolean variable S (1 = start; 0 = run or off), and
the clutch pedal position with the Boolean variable C (1 = clutch
pedal depressed; 0 = clutch pedal in normal, unpressed position).
Write a Boolean expression for the starter solenoid status, given
the start switch (S) and clutch (C) statuses. Then, draw a logic
gate circuit to implement this Boolean function.

You might also like