Arithmetic and Bitwise Operations on Binary Data
[Pages:46]Saint Louis University
Arithmetic and Bitwise Operations on Binary Data
CSCI 2400: Computer Architecture ECE 3217: Computer Architecture and Organization
Instructor: David Ferry
Slides adapted from Bryant & O'Hallaron's slides by Jason Fritts
1
Saint Louis University
Arithmetic and Bitwise Operations
Operations
Bitwise AND, OR, NOT, and XOR Logical AND, OR, NOT Shifts Complements
Arithmetic
Unsigned addition Signed addition Unsigned/signed multiplication Unsigned/signed division
2
Basic Processor Organization
Register file (active data)
We'll be a lot more specific later...
Arithmetic Logic Unit (ALU)
Performs signed and unsigned
arithmetic
Performs logic operations Performs bitwise operations
Many other structures...
CPU
Register File
Saint Louis University
ALU
Memory
3
Saint Louis University
Boolean Algebra
Developed by George Boole in 19th Century
Algebraic representation of logic
Encode "True" as 1 and "False" as 0
And
Or
A&B = 1 when both A=1 and B=1 A|B = 1 when either A=1 or B=1
Not
~A = 1 when A=0
Exclusive-Or (Xor)
A^B = 1 when either A=1 or B=1, but not both
4
General Boolean Algebras
Saint Louis University
Operate on Bit Vectors
Operations applied bitwise
Bitwise-AND operator:
&
Bitwise-NOR operator:
|
Bitwise-XOR operator:
^
Bitwise-NOT operator:
~
01101001 01101001 01101001 & 01010101 | 01010101 ^ 01010101
0011000000000011 0011111111110011 0000111111110000
~ 01010101 1100110011001100
All of the Properties of Boolean Algebra Apply
5
Quick Check
Saint Louis University
Operate on Bit Vectors
Operations applied bitwise
Bitwise-AND operator:
&
Bitwise-NOR operator:
|
Bitwise-XOR operator:
^
Bitwise-NOT operator:
~
01100110 11110000 01101001 & 00101111 | 01010101 ^ 00001111
0010010000010110 011110101 0001111010110100
~ 00101111 1101100110001000
All of the Properties of Boolean Algebra Apply
6
Bit-Level Operations in C
Saint Louis University
Operations &, |, ~, ^ Available in C
Apply to any "integral" data type
long, int, short, char, unsigned
View arguments as bit vectors Arguments applied bit-wise
Examples (char data type):
in hexadecimal
in binary
~0x41 0xBE // ~0x00 0xFF // 0x69 & 0x55 0x41 // 0x69 | 0x55 0x7D //
~010000012 ~000000002 011010012 & 010101012 011010012 | 010101012
101111102 111111112 010000012 011111012
7
Contrast: Logic Operations in C
Saint Louis University
Contrast to Logical Operators
&&, ||, !
View 0 as "False" Anything nonzero as "True" Always return 0 or 1 Early termination
Examples (char data type):
!0x41 0x00 !0x00 0x01 !!0x41 0x01
0x69 && 0x55 0x01 0x69 || 0x55 0x01 p && *p
// avoids null pointer access
8
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- python basic operators picone press
- basics of python programming
- python bitwise operators example rxjs ggplot2 python
- python quick revision tour
- pcap programming essentials in python
- python basic operators rxjs ggplot2 python data
- 13a05806 python programming
- arithmetic and bitwise operations on binary data
- python tutorials and notes
Related searches
- airborne operations on d day
- convert binary data to text
- arithmetic and geometric sequences worksheet
- dynamics 365 operations on premise
- binary data converter
- arithmetic and geometric sequences and series
- numpy operations on array
- python write binary data to file
- read binary data in python
- python convert binary data to string
- bitwise operations in python
- read binary data python