0% found this document useful (0 votes)
20 views45 pages

Binary Representation and Logic Concepts

Uploaded by

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

Binary Representation and Logic Concepts

Uploaded by

tuana.semsek
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as KEY, PDF, TXT or read online on Scribd

COMP101

Bits&Bytes-Binary RepresentationsBoolean Algebra Logic Gates


Binary Codes and Units
Since the CPU can execute only machine code instructions
and operate on data in binary. All the data must be represented
in binary.
The fundemental building block of digital information is the
binary digit or bit, which represents a single 0 or 1 state. Bit is
stored on computer memory, which is the smallest unit.
To represent large amount of data, bits are organized into
grouped of four, eight, sixteen, 32, 64 bits, called nybble, byte,
words, long words and very long words respectively. These are
referred as units of data.
Binary representations of numbers
64 in binary: 1000000
72 in binary: 1001000
85 in binary: 1010101
Binary representations of signed numbers

Binary digits can represent not only whole numbers but also
other forms of data, including signed integers, decimal numbers,
and characters. For example, to represent signed integers, we
can use the leftmost bit of a number to represent the sign, with 0
meaning positive (+) and 1 meaning negative (–). The remaining
bits are used to represent the magnitude of the value. This form
of signed integer representation is termed sign/magnitude
notation, and it is one of a number of different techniques.
Binary representations of signed numbers
Signed Bit Representation
For example, to represent the quantity -49 in sign/magnitude, we could use
seven binary digits with 1 bit for the sign and 6 bits for the magnitude:1 1 1 0 0
01
-49 (2^5 + 2^4 + 2^0 = 32 + 16 + 1 = 49)
The value +3 would be stored like this:
0 000011
+ 3 (2^1 + 2^0 = 2 + 1 = 3)
Signed Bit Representation
In the signed integer representation method the following rules are
followed:
1. The MSB (Most Significant Bit) represents the sign of the Integer.
2. Magnitude is represented by other bits other than MSB i.e. (n-1) bits
where n is the no. of bits.
3. If the number is positive, MSB is 0 else 1.
4. The range of signed integer representation of an n-bit number is
given as –(2^{n-1}-1) to (2)^{n-1}-1.
Signed Bit Representation
Drawbacks:
1. For 0, there are two representations: -0 and +0 which should not be
the case as 0 is neither –ve nor +ve.
2. Out of 2^n bits for representation, we are able to utilize only 2^{n-1}
bits.
3. Numbers are not in cyclic order i.e. After the largest number (in this, for
example, +7) the next number is not the least number (in this, for
example, +0).
4. For negative numbers signed extension does not work.
Signed Bit Representation
Signed Bit Representation
1’s Complement representation of a signed integer
In 1’s complement representation the following rules are used:
1-For +ve numbers the representation rules are the same as signed integer representation.
2-For –ve numbers, we can follow any one of the two approaches:
Write the +ve number in binary and take 1’s complement of it.
1’s complement of 0 = 1 and 1’s complement of 1 = 0
Example:
(-5) in 1’s complement:
+5 = 0101
-5 = 1010

Write Unsigned representation of 2^n -1-X for –X.


Example: –X = -5 for n=4 2^4-1-5=10 ->1010 (Unsigned)
1’s Complement representation of a signed
integer
3- The range of 1’s complement integer representation of n-bit number is given as –
(2^{n-1}-1) to 2^{n-1}-1.
1’s Complement Representation:
1’s Complement representation of a signed
integer
Drawbacks:
For 0, there are two representations: -0 and +0 which should not be the case
as 0 is neither –ve nor +ve.
Out of 2^n bits for representation, we are able to utilize only 2^{n-1} bits.

Merits over Signed bit representation:


1. Numbers are in cyclic order i.e. after the largest number (in this, for example,
+7) the next number is the least number (in this, for example, -7).
2. For negative number signed extension works.
1’s Complement representation of a
signed integer
As it can be seen, for +ve as well as -ve
representation, if 4 bits are extended to 5
bits there is a need to just append 0/1
respectively in MSB.
2’s Complement representation
In 2’s Complement representation the following rules are used:
1. For +ve numbers, the representation rules are the same as signed integer representation.
2. For –ve numbers, there are two different ways we can represent the number.
Write an unsigned representation of 2^n-X for –X in n-bit representation.
Example:
(-5) in 4-bit representation
2^4-5=11 -→1011(unsigned)

Example:
Write a representation of +X and take 2’s Complement. (-5) in 2’s complement
(+5) = 0101
To take 2’s complement simply take 1’s complement and add 1 to it. 1’s complement of (+5) = 1010
Add 1 in 1010: 1010+1 = 1011
Therefore (-5) = 1011
2’s Complement representation

3. Range of representation of n-bit is –(2^{n-1} )


to (2)^{(n-1)-1}.
Merits:
No ambiguity in the representation of 0.
Numbers are in cyclic order i.e. after +7 comes -8.
Signed Extension works.
The range of numbers that can be represented
using 2’s complement is very high.
Due to all of the above merits of 2’s complement
representation of a signed integer, binary numbers
are represented using 2’s complement method
instead of signed bit and 1’s complement.
Binary Fractions
Similar to decimal fractions, binary numbers can also be
represented as unsigned fractional numbers by placing the binary
digits to the right of the decimal point or in this case, binary point.
Thus all the fractional digits to the right of the binary point have
respective weightings which are negative powers of two, creating
binary fractions. In other words, the powers of 2 are negative.
Binary Fractions

So for the fractional binary numbers to the


right of the binary point, the weight of each
digit becomes more negative giving: 2-1, 2-2, 2-
3
, 2-4, and so on as shown.
Thus if we take the binary fraction of 0.1011(2)
then the positional weights for each of the
digits is taken into account giving its decimal
equivalent of:
Binary Fractions
Converting binary fraction to decimal fraction examples:
Binary Fractions
Converting Decimal to a Binary Fraction
The conversion of decimal fractions to binary fractions is
achieved using a method similar to that we used for integers.
However, this time multiplication is used instead of division with
the integers instead of remainders used with the carry digit being
the binary equivalent of the fractional part of the decimal number.
Binary Fractions
To find the binary fraction equivalent of the decimal fraction: 0.8125 (10)

0.8125 (multiply by 2) = 1.625 = 0.625 carry 1 (MSB)

0.625 (multiply by 2) = 1.25 = 0.25 carry 1 (↓)

0.25 (multiply by 2) = 0.50 = 0.5 carry 0 (↓)

0.5 (multiply by 2) = 1.00 = 0.0 carry 1 (LSB)

Thus the binary equivalent of 0.812510 is therefore: 0.1101 (2) ← (LSB)


Binary Fractions
Find the binary fraction equivalent of the following decimal number: 54.6875
First we convert the integer 54 to a binary number in the normal way using successive
division from above.
54 (divide by 2) = 27 remainder 0 (LSB)
27 (divide by 2) = 13 remainder 1 (↑)
13 (divide by 2) = 6 remainder 1 (↑)
6 (divide by 2) = 3 remainder 0 (↑)
3 (divide by 2) = 1 remainder 1 (↑)
1 (divide by 2) = 0 remainder 1 (MSB)
Thus the binary equivalent of 5410 is therefore: 1101102
Binary Fractions
Next we convert the decimal fraction 0.6875 to a binary fraction using
successive multiplication.
0.6875 (multiply by 2) = 1.375 = 0.375 carry 1 (MSB)
0.375 (multiply by 2) = 0.75 = 0.75 carry 0 (↓)
0.75 (multiply by 2) = 1.50 = 0.5 carry 1 (↓)
0.5 (multiply by 2) = 1.00 = 0.0 carry 1 (LSB)
Thus the binary equivalent of 0.687510 is therefore: 0.10112 ← (LSB)
Hence the binary equivalent of the decimal number: 54.687510 is 110110.10112
Binary Fractions
Convert the Fractional Part (0.37842) to Binary

0.37842 in binary is approximately 0.0110000011.


Binary Representation of Text
Textual Information. To represent textual material in binary, the
system assigns to each printable letter or symbol in our alphabet
a unique number (this assignment is called a code mapping), and
then it stores that symbol internally using the binary equivalent of
that number. For example, here is one possible mapping of
characters to numbers, which uses 8 bits to represent each
character.
ASCII (American Standard Code for
Information Interchange)
Historical Background: Developed in the early 1960s,
ASCII was the first widely adopted standard for representing text
in computers.7-bit Encoding: ASCII originally used 7 bits to
represent each character, allowing for 128 characters (including
control characters, uppercase and lowercase letters, digits, and
punctuation marks).
Extended ASCII: Later, 8-bit ASCII was introduced to extend
the character set to 256 characters, allowing for more symbols
and additional characters used in different languages.
ASCII (American Standard Code for
Information Interchange)
ASCII (American Standard Code for
Information Interchange)
Here is some interesting information that you can derive from this chart.
The left hand section contains the first 32 codes, those with hex values
00 through 1F, which are known as the 'non-printing' characters. These
codes were used to supervise or to 'control' the data flow.
The next section contains 32 more codes, those with hex values 20
through 3F. These are the first of the printable characters and they
consist mostly of punctuation but they also contain the numbers 0
through 9. Notice how the ASCII code (hex) for a number relates to
the number itself.
ASCII (American Standard Code for
Information Interchange)
This is what makes it so easy to convert numbers to and from
ASCII. If you have the ASCII code for a number you can
either subtract 30h or mask off the upper four bits and you will
be left with the number itself.
The third and fourth sections:
These sections contains the rest of the ASCII codes, those with
hex values 40 through 7F. Here is where you find the alphabetic
characters and some more punctuation.
UNICODE
Unicode is a universal character encoding standard designed to
provide a unique number for every character, regardless of the platform,
device, application, or language. It aims to represent characters from all
writing systems around the world, ensuring consistency and
interoperability.
Universal Character Set: Unicode provides a unified way of
representing text from different languages and scripts across the world.
It aims to represent every character used in writing systems globally.
Encoding Forms: Unicode has different encoding forms, such as UTF-
8, UTF-16, and UTF-32:
UNICODE
UTF-8: A variable-length encoding that uses 1 to 4 bytes to
represent each character. It is backward-compatible with
ASCII, meaning that the first 128 characters are encoded
identically to ASCII.
UTF-16: Uses 2 bytes or 4 bytes per character.
UTF-32: Uses 4 bytes for every character, providing a fixed-
length representation.
UNICODE
Unicode was adopted to solve the limitations of ASCII and provide a
comprehensive solution for representing text in the global, interconnected
world:
1. Universal Coverage:
Unicode was developed to be a universal standard that can represent all
the characters from all writing systems around the [Link] supports
scripts from over 150 languages, as well as symbols, emojis, and even
ancient scripts. This makes it possible to represent text from any culture
or language using a single encoding standard.
UNICODE
1. Scalability:
Unlike ASCII, which was limited to a maximum of 256 characters,
Unicode can represent over 1.1 million characters.
This makes Unicode highly scalable, allowing it to keep
expanding as new characters or symbols are needed.
UNICODE
1. Compatibility with ASCII:
UTF-8 (a common Unicode encoding) is backward-compatible
with ASCII. This means that any valid ASCII text is also valid
UTF-8 text, which made transitioning to Unicode much easier.
Text files that only contain ASCII characters can be read
seamlessly by systems that use UTF-8.
UNICODE
1. Support for Symbols and Emojis:
Unicode also includes mathematical symbols, currency symbols,
punctuation, and emojis, allowing for richer text representation
that is crucial in modern communication.
The ability to include emojis and special symbols has become an
essential feature of Unicode, particularly in digital
communication.
UNICODE
Codes 256 to 912: Special Characters and Accents
Boolean Logic
The construction of computer circuits is based on the branch of
mathematics and symbolic logic called Boolean logic . This
Area of mathematics deals with rules for manipulating two logic
values true and false and it is used to construct circuits that
perform operations such as adding numbers, comparing numbers
and fetching instructions. These ideas are part of branch of
computer science known as hardware design, also called logic
design.
Boolean Logic
Building Boolean expressions
Boolean logic only works when an expression can be TRUE or
FALSE. For example, the expression 3 + 8 isn’t a Boolean
expression because it’s not being compared or related to
something else.
But the expression 3 + 8 = 10 is a Boolean expression because
we can now evaluate each side and see if the reported
relationship between them is TRUE or FALSE (in this case, it’s
FALSE).
Boolean Logic

For example, let’s suppose that we’ve


assigned these values to variables x and y
somewhere in our code:
x is 7
y is 3
Now, we can build Boolean expressions using
our variables:
Boolean operators
In Boolean logic, the tree basic operations used to construct
Boolean expressions are AND, OR, and NOT. (There are other
Boolean operators such as XOR, NOR, NAND).
TRUTH TABLES
Boolean Logic

Given Values:𝑥=5, 𝑦=10, 𝑧=15


(x=5) AND (y=11) OR ([x+y]=z)

Step-by-Step Evaluation:
Substitute the GivenValues:
(5=5) AND (10=11) OR ([5+10]=15)
Evaluate Each Condition:
5=5 is True. 10=11 is False. 5+10=15 is True.
Boolean Expression:The expression now becomes:
True AND False OR True
Order of Operations: AND is evaluated before OR.
So, evaluate True AND False first, which is False.
The expression now becomes:
False OR True:
Evaluate the OR:
False OR True is True.
Gates
A gate is an electronic device that operates on a collection of
binary inputs to produce a binary output. That is, it transforms a
set of (0, 1) input values into a single (0, 1) output value
according to a specific transformation rule. Although gates can
implement a wide range of different transformation rules, the
ones we are concerned with in this section are those that
implement the Boolean operations AND, OR, and NOT
introduced in the previous section.
Gates
Gates
A NOT gate can be constructed from a single
transistor, as shown in Figure, in which the
collector is connected to the power supply
(Logical-1) and the emitter is connected to
the ground (Logical-0). If the control line of
the transistor (labeled Input) is set to 1, then
the transistor is in the ON state, and it passes
current through to the ground. In this case,
the voltage on the line labeled Output is 0.
However, if Input is set to 0, the transistor is
in the OFF state, and it blocks passage of
current to the ground. Instead, the current is
transmitted to the Output line, producing a
value of 1.

You might also like