Bits and Bytes Boolean algebra Expressing in C

Slides:



Advertisements
Similar presentations
CSE 20 Lecture 9 Boolean Algebra: Theorems and Proofs CK Cheng April 26, 2011 Lecture notes 1.
Advertisements

CSCE 212 Computer Organization Lecture 2 Data Representation.
Bits and Bytes 4/2/2008 Topics Physics, transistors, Moore’s law Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers.
Bits and Bytes CS 213 Aug. 27, 1998 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and.
Bits and Bytes January 17, 2002 Topics Why bits? Representing information as bits –Binary/Hexadecimal –Byte representations »numbers »characters and strings.
Bits and Bytes Topics Physics, transistors, Moore’s law Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters.
ICS 2005 Instructor: Peter A. Dinda TA: Bin Lin Recitation 2.
Bits and Bytes January 15, 2004 Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings.
Bits and Bytes Topics Why bits? Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
February 4, 2003 CSCE 212 Computer Architecture Lecture 3 Representing Integers.
1 CSE 20: Lecture 7 Boolean Algebra CK Cheng 4/21/2011.
Fabián E. Bustamante, Spring 2007 Bits and Bytes Today Why bits? Binary/hexadecimal Byte representations Boolean algebra Expressing in C.
CS 270: Computer Organization Bits, Bytes, and Integers
Bits and Bytes Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C.
Lecture 3: Computation and Representation CS 2011 Fall 2014, Dr. Rozier.
1. 3 x = x 3 2. K + 0 = K (3 + r) = (12 + 3) + r 4. 7 (3 + n) = n Name the Property Commutative of Multiplication Identity of Addition.
Bits and Bytes Topics Why bits? Tell me Representing information as bits Binary/Hexadecimal Byte representations »numbers »characters and strings »Instructions.
Bits, Bytes, and Integers Topics Representing information as bits Bit-level manipulations Boolean algebra Expressing in C Representations of Integers Basic.
1 Saint Louis University Arithmetic and Bitwise Operations on Binary Data CSCI 224 / ECE 317: Computer Architecture Instructor: Prof. Jason Fritts Slides.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
Bits and Bytes September 2, 2004 Topics Why bits? Representing information as bits Binary / Hexadecimal Byte representations »Numbers »Characters and strings.
– 1 – Number Systems Number of symbols = base of the system Most intuitive -- base 10 (decimal system) counting on fingertips symbols
Boolean Algebras Lecture 27 Section 5.3 Wed, Mar 7, 2007.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Bits and Bytes Boolean Algebra ( ) Boolean algebra Expressing in C.
(2 + 1) + 4 = 2 + (1 + 4) Associative Property of Addition.
Bits and Bytes Topics Why bits? Representing information as bits
Real Number and the number Line. Number System Real numbers: is number that can be positive or negative and have decimal places after the point. Natural.
Properties Objective: To use the properties of numbers. Do Now 1.) = 3.) ( 2  1 )  4 = 2.) =4.) 2  ( 1  4 ) =
by D. Fisher (2 + 1) + 4 = 2 + (1 + 4) Associative Property of Addition 1.
(2 + 1) + 4 = 2 + (1 + 4) Associative Property of Addition.
Distributive Commutative Addition Zero Property Additive Inverse 0 Multiplicative Identity Commutative Multiplication Multiplicative Inverse Additive Identity.
Axioms for Rational Numbers 9/14-9/15. Natural Numbers – Numbers used for counting: 1, 2, 3, and so on. Whole Numbers – Natural numbers and zero: 0, 1,
Lecture 3: Boolean Algebra and Registers CS 2011 Spring 2016, Dr. Rozier.
Carnegie Mellon Bits, Bytes, and Integers (1-2) /18-243: Introduction to Computer Systems 2 nd Lecture, 19 May 2011 Instructors: Gregory Kesden.
(2 x 1) x 4 = 2 x (1 x 4) Associative Property of Multiplication 1.
Boolean Algebras Lecture 24 Section 5.3 Wed, Mar 22, 2006.
1 Manipulating Information (1). 2 Outline Bit-level operations Suggested reading –2.1.7~
Properties of Algebra. 7 + ( ) = ( ) + 9.
Number Properties. Commutative Property of Addition Words: In a sum, you can add terms in any order. Numbers: 5 + (-6) Algebra: a + b b + a.
Computer Architecture & Operations I
Morgan Kaufmann Publishers
Revision of IO Streams printf scanf.
Today’s Instructor: Randy Bryant
Digital Technology.
Properties of Operations
Commutative Property of Addition
2.0 FUNDAMENTALS OF JAVA PROGRAMMING LANGUAGE
Bits, Bytes, and Integers CSE 238/2038/2138: Systems Programming
Instructor: David Ferry
Let’s make remembering these properties a little more memorable.
Properties of Addition and Multiplication
Properties.
Representing Information
Data III & Integers I CSE 351 Winter 2017
Bits and Bytes Topics Representing information as bits
Bits, Bytes, and Integers January 16, 2008
Bits and Bytes Topics Representing information as bits
Bits and Bytes Topics Representing information as bits
Bits, Bytes, and Integers 2nd Lectures
Bits and Bytes Topics Representing information as bits
“The Class That Gives CMU Its Zip!”
Memory, Data, & Addressing II CSE 351 Summer 2018
Bits and Bytes Topics Representing information as bits
Comp Org & Assembly Lang
Comp Org & Assembly Lang
Operations and Arithmetic
“The Class That Gives CMU Its Zip!”
“The Class That Gives CMU Its Zip!”
Lecture 2: Bits, Bytes, Ints
Presentation transcript:

Bits and Bytes Boolean algebra Expressing in C

Boolean Algebra Developed by George Boole in 19th Century Algebraic representation of logic Encode “True” as 1 and “False” as 0 Or A|B = 1 when either A=1 or B=1 And A&B = 1 when both A=1 and B=1 Not ~A = 1 when A=0 Exclusive-Or (Xor) A^B = 1 when either A=1 or B=1, but not both

Integer Algebra Integer Arithmetic Z, +, *, –, 0, 1 forms a “ring” Addition is “sum” operation Multiplication is “product” operation – is additive inverse 0 is identity for sum 1 is identity for product

Boolean Algebra Boolean Algebra {0,1}, |, &, ~, 0, 1 forms a “Boolean algebra” Or is “sum” operation And is “product” operation ~ is “complement” operation (not additive inverse) 0 is identity for sum 1 is identity for product

Boolean Algebra  Integer Ring Commutativity A | B = B | A A + B = B + A A & B = B & A A * B = B * A Associativity (A | B) | C = A | (B | C) (A + B) + C = A + (B + C) (A & B) & C = A & (B & C) (A * B) * C = A * (B * C) Product distributes over sum A & (B | C) = (A & B) | (A & C) A * (B + C) = A * B + B * C Sum and product identities A | 0 = A A + 0 = A A & 1 = A A * 1 = A Zero is product annihilator A & 0 = 0 A * 0 = 0 Cancellation of negation ~ (~ A) = A – (– A) = A

Boolean Algebra  Integer Ring Boolean: Sum distributes over product A | (B & C) = (A | B) & (A | C) A + (B * C)  (A + B) * (B + C) Boolean: Idempotency A | A = A A + A  A “A is true” or “A is true” = “A is true” A & A = A A * A  A Boolean: Absorption A | (A & B) = A A + (A * B)  A “A is true” or “A is true and B is true” = “A is true” A & (A | B) = A A * (A + B)  A Boolean: Laws of Complements A | ~A = 1 A + –A  1 “A is true” or “A is false” Ring: Every element has additive inverse A | ~A  0 A + –A = 0

Properties of & and ^ (Xor) Boolean Ring {0,1}, ^, &, , 0, 1 Identical to integers mod 2  is identity operation:  (A) = A A ^ A = 0 Property Boolean Ring Commutative sum A ^ B = B ^ A Commutative product A & B = B & A Associative sum (A ^ B) ^ C = A ^ (B ^ C) Associative product (A & B) & C = A & (B & C) Prod. over sum A & (B ^ C) = (A & B) ^ (B & C) 0 is sum identity A ^ 0 = A 1 is prod. identity A & 1 = A 0 is product annihilator A & 0 = 0 Additive inverse A ^ A = 0

General Boolean Algebras Operate on Bit Vectors Operations applied bitwise All of the Properties of Boolean Algebra Apply 01101001 & 01010101 01000001 01101001 | 01010101 01111101 01101001 ^ 01010101 00111100 ~ 01010101 10101010 01000001 01111101 00111100 10101010

Bit-Level Operations in C Operations &, |, ~, ^ Available in C Apply to any “integral” data type long, int, short, char View arguments as bit vectors Arguments applied bit-wise Examples (Char data type) ~0x41 --> 0xBE ~010000012 --> 101111102 ~0x00 --> 0xFF ~000000002 --> 111111112 0x69 & 0x55 --> 0x41 011010012 & 010101012 --> 010000012 0x69 | 0x55 --> 0x7D 011010012 | 010101012 --> 011111012

Contrast: Logic Operations in C 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

Cool Stuff with Xor Bitwise Xor is form of addition void funny(int *x, int *y) { *x = *x ^ *y; /* #1 */ *y = *x ^ *y; /* #2 */ *x = *x ^ *y; /* #3 */ } Bitwise Xor is form of addition With extra property that every value is its own additive inverse A ^ A = 0 *x *y Begin A B 1 B A^B 2 (A^B)^B = A A^B 3 A (A^B)^A = B End A B