Bits, Data types, and Operations: Chapter 2
-
Upload
kiona-burke -
Category
Documents
-
view
48 -
download
2
description
Transcript of Bits, Data types, and Operations: Chapter 2
![Page 1: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/1.jpg)
Bits, Data types, and Operations: Chapter 2
COMP 2610Dr. James Money
COMP 2610
1
![Page 2: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/2.jpg)
Operations on Bits
So far, we have seen we can perform
addition and subtraction on binary patterns
Recall the meaning of ALU – arithmetic and
logic unit
The other set of operations is logical
operations
![Page 3: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/3.jpg)
Operations on Bits
Recall that the name logical is historical in origin
It refers to the fact that a bit has two values 0
and 1
These refer to false and true, respectively
We consider several basic logical functions of
the ALU
![Page 4: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/4.jpg)
AND Function
AND is a binary logical function
It takes two source operands, and produces one
result
Each source is a logical values, either 0 or 1
The output of AND is 1 only if both the source
values are 1
Otherwise the output is 0
![Page 5: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/5.jpg)
AND Function
A convenient way to represent the behavior of
logical operation is the truth table
A truth table has n+1 columns and 2n rows
The n columns refer to the source operands and
the +1 refers to the output
Each value has two possible values, so there
are 2n choices
![Page 6: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/6.jpg)
AND Function
A B AND
0 0 0
0 1 0
1 0 0
1 1 1
![Page 7: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/7.jpg)
AND Function
AND 1 0
1 1 0
0 0 0
AND True False
True True False
False False False
![Page 8: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/8.jpg)
AND Function
We can also apply the AND operation to two
bits patterns of m bits each
We apply the AND function to each pair of
bits in the two source operands
This operation is called a bitwise AND
![Page 9: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/9.jpg)
AND Function
IF c=a AND b where a=0011101001101001
and b=0101100100100001, what is c?
a: 0011101001101001
b: 0101100100100001
c: 0001100000100001
![Page 10: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/10.jpg)
AND Function
Suppose we have an 8 bit pattern called A in
which only the two right-most bits are
significant
The computer will do one of four tasks
depending on the value of these two bits
How do we isolate these two bits?
![Page 11: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/11.jpg)
AND Function
We can use a bitmask to get this value
The bitmask should be 1 for the bits you are
interested in and 0 elsewhere
So we would use the bitmask 00000011
Then we apply the A AND bitmask
![Page 12: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/12.jpg)
AND Function
If A=01010110,A: 01010110
Bitmask: 00000011
00000010
If A=11111100,A: 11111100
Bitmask: 00000011
00000000
![Page 13: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/13.jpg)
OR Function
OR is also a binary logical function
It requires two source operand and produces one
output
The output of OR is only 0 if both inputs are 0
Otherwise, it is 1
We can apply the OR operation to m bits the
same as the AND function
![Page 14: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/14.jpg)
OR Function
A B OR
0 0 0
0 1 1
1 0 1
1 1 1
![Page 15: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/15.jpg)
OR Function
OR 1 0
1 1 1
0 1 0
AND True False
True True True
False True False
![Page 16: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/16.jpg)
OR Function
Some times this is called the inclusive-OR
function to differentiate it from the exclusive
OR operator
Let a=0011101001101001 and
b=0101100100100001
What is c=a OR b?
![Page 17: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/17.jpg)
OR Function
a: 0011101001101001
b: 0101100100100001
c: 0111101101101001
![Page 18: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/18.jpg)
NOT Function
NOT is a unary logical function
That is, it only takes one source operand, and
outputs one result
This is also known as the complement operation
We says the output is formed by inverting the
bits
![Page 19: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/19.jpg)
NOT Function
A NOT
0 1
1 0
![Page 20: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/20.jpg)
NOT Function
We can apply the NOT function to a single m
bit pattern the same way we apply it to two m
bit patterns for AND and OR
Let c=NOT a and a=0011101001101001
a: 0011101001101001
c: 1100010110010110
![Page 21: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/21.jpg)
XOR Function
The Exclusive-OR or XOR function is a binary
logical function with two source operands and
one result
The output of XOR is 1 two sources are different
Otherwise, the output is 0
We can apply this to m bit patterns as well
![Page 22: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/22.jpg)
XOR Function
A B XOR
0 0 0
0 1 1
1 0 1
1 1 0
![Page 23: Bits, Data types, and Operations: Chapter 2](https://reader035.fdocuments.in/reader035/viewer/2022081504/568132af550346895d99620f/html5/thumbnails/23.jpg)
XOR Function
Let a=0011101001101001,
b=01011001001000001, and find c=a XOR b
a: 0011101001101001
b: 0101100100100001
c: 0110001101001000
We can use XOR to determine if two bit patterns
are identical!