You are on page 1of 23

3.

2
OPERATIONS
ON DATA
Subtitle
Content

• 1 Logic
• 2 Shift
• 3.Arithmetic operations

2
1. LOGIC

• Logic operations refer to those operations that apply the


same basic operation on individual bits of a pattern, or on
two corresponding bits in two patterns.
• A logic operation at the pattern level is n logic operations,
of the same type, at the bit level where n is the number of
bits in the pattern.
• A bit can take one of the two values: 0 or 1. If we
interpret 0 as the value false and 1 as the value
true,
1. LOGIC
• NOT: phủ định
• AND: phép nhân
• OR: phép cộng ( ngoại trừ 1 or
1 =1)
• Xor: như or, ngoại trừ 1+1=0
( k nhớ)
• 1+1=0
AND: phép nhân// +

0110 1110
xOr 1011 1101
------------------------------
11 01 0011
OR: phép cộng
01101110
01101110
Or 10101101
xOr 10101101
------------------------------
------------------------------
11101111
11000011
Phep cong k nho
1+1= 0
2 - Shift Operations

2.1 Logical shift ( dịch trái, phải)


2.2 Circular Shift Operations (dịch tròn trái, phải)
2.3 Arithmetic shift operation
2.1 Logical shift ( dịch trái, phải)

a. dịch trái
- Thêm 0 vào bên phải dãy bit, dịch trái các bít còn lại, lost bit trái ngoài
cùng:
b. Dịch phải
- Thêm 0 vào bên trái dãy bit, dịch phải các bít còn lại, lost bit phải ngoài
cùng
2.1 Logical shift ( dịch trái, phải)

Example 3.7
Use a logical left shift operation on the bit pattern 10011001.
Solution

10011001 => 0 1001100 1


10011001 => 10011001 0
2.1 Logical shift ( dịch trái, phải)

A= 1010 = 10
a. dịch trái: 1 0100 = 4
b. Dịch phải
2.2. Circular Shift Operations

a. dịch tròn trái


- Bit bên trái copy vào phía ben phải, các bit khác dịch trái
b. Dịch tròn phải
- Bit ben phai copy vao phía bên trai, các bit khác dịch phải
2.2. Circular Shift Operations

1. dịch tròn trái: 0101010111 …= 101010111


2. Dịch tròn phải: ….0101010111 =1 010101
2.2. Circular Shift Operations

A= 1010111
1. dịch tròn trái
2. Dịch tròn phải
2.3 Arithmetic shift operations

a. dịch toán học trái


- tượng tự nhu dịch trái logical
b.Dịch toán học phải
- Copy 2 lần bit bên trái xuống, các bit khác dịch phải
2.3 Arithmetic shift operations

000011100 =28
000111000= 56 = 28.2
Dich toan hoc trai: de hthuc hien phep
nhan 2 lan
---------------------------
000011100= 28
000011100 = 14 = 28:2
Dich toan hoc phai: chia 2
110 10

2. Not B +1 = bu 2 cua B
1. Bu 2 cua B Not B = 011011111
001 10 + 1
---------------------------
00 1 1 0
3.1 Addition and subtraction of integers in two’s
complement format

• Nếu R=A+B : cứ cộng 2 dãy nhị phân là xong


• Nếu R=A-B  R= A+ (bù 2 của B)
3.1 Addition and subtraction of integers in two’s
complement format

• A= 1011 • A= 1010 = - (0110 =6)


• B= 0110 • B= 0111 = +7  100 1
• R= A-B= A+ bu 2 cua B
• R= A+B
-----------------
-----------------
1 0 1 0
1011 + 1 0 0 1
+ 0110 --------------------
--------------- 10 0 1 1 =-13
10 0’ 0’ 1 01101= 13
R=A-B= A+ (bu 2 cua B) ???

Retrieved binary  integer ( two’s complement format)


0…….. // Binary  decimal
1………………..
Thuc hien co che bu 2  [binary->decimal] retrieved
A-B = A+ (-B)= A+ (bu 2 cua B)
A = 0110 B = 0011

•R=A+B •R=A-B
=6+3 = 9 =-----------
-----------
0110
0110
+ 0011
+ 1101
------------- -------------
1001 10011 = -,…
Addition and subtraction of integers in two’s
complement format
A= 0101= +5 A= 0101 = +5
B= 0110= +6
R=A+B = 11 B= 0110 =+6  bu 2: 10 10
0101 R=A-B = -1
+ 0110
-------------- 0101
1 0 1 1 =11 + 1010
--------------
1 111 =- 1
Bu 2: 0001 = 1
3.2 Addition and subtraction of integers in sign-
and-magnitude

= As Am = -5
= Bs Bm= + 6

11

You might also like