Bit-String Flicking.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
Bit Manipulation. Binary Numbers Base 10 numbers are represented by sum of digits times powers of 10. For example: 234 = 2* * *10 0 Binary.
All the Operators. Precedence An operator with higher precedence is done earlier (prededes) one with lower precedence –A higher precedence is indicated.
Logical and Shift operations A particular bit, or set of bits, within the byte is set to 1 or 0 depending on conditions encountered during the execution.
Is ASCII the only way? For computers to do anything (besides sit on a desk and collect dust) they need two things: 1. PROGRAMS 2. DATA A program is a.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Expressions and Operators Program Style.
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Binary Operations Math/Logical. Binary Math Decimal Addition Example ) Add = 15 Write down 5, carry ) Add 3 +
Solving Equations In Quadratic Form There are several methods one can use to solve a quadratic equation. Sometimes we are called upon to solve an equation.
6.1 The Fundamental Property of Rational Expressions.
Table of Contents Solving Equations In Quadratic Form There are several methods one can use to solve a quadratic equation. Sometimes we are called upon.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Computers Organization & Assembly Language
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Ryan Chu. Arithmetic Expressions Arithmetic expressions consist of operators, operands, parentheses, and function calls. The purpose is to specify an.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Sequences and Summations
Selection Boolean What is Boolean ? Boolean is a set with only two values : –true –false true and false are standard identifiers in Pascal, called Boolean.
Solving Polynomial Equations – Factoring Method A special property is needed to solve polynomial equations by the method of factoring. If a ∙ b = 0 then.
A Quadratic Equation is an equation that can be written in the form Solving Quadratic Equations – Factoring Method Solving quadratic equations by the factoring.
Set A formal collection of objects, which can be anything May be finite or infinite Can be defined by: – Listing the elements – Drawing a picture – Writing.
REGISTER TRANSFER LANGUAGE MICROOPERATIONS. TODAY OUTLINES Logic Microoperations Shift Microoperations.
Programming Fundamental Slides1 Data Types, Identifiers, and Expressions Topics to cover here: Data types Variables and Identifiers Arithmetic and Logical.
Example: 3x 2 + 9x + 6. Solving Quadratic Equations.
AEEE2031 Data Representation and Numbering Systems.
1 Operators and Expressions. Expressions Combination of Operators and Operands Example 2 * y + 5 Operands Operators.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Table of Contents Solving Polynomial Equations – Factoring Method A special property is needed to solve polynomial equations by the method of factoring.
1 Program Development  The creation of software involves four basic activities: establishing the requirements creating a design implementing the code.
Operators & Expressions
Solving Linear Systems by Substitution
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 1 Number Systems Digital Electronics. Topics discussed in last lecture Digital systems Advantages of using digital signals over analog. Disadvantages.
0 Chap.2. Types, Operators, and Expressions 2.1Variable Names 2.2Data Types and Sizes 2.3Constants 2.4Declarations 2.5Arithmetic Operators 2.6Relational.
Department of Electronic & Electrical Engineering Expressions operators operands precedence associativity types.
CSC 3210 Computer Organization and Programming
Department of Electronic & Electrical Engineering Lecture 3 IO reading and writing variables scanf printf format strings "%d %c %f" Expressions operators.
Notes 2.1 Order of Operations PEMDAS If an expression has only numbers and symbols, it is a numerical expression. If it has a variable it is a variable.
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
Rational Expressions relational operators logical operators order of precedence.
Operators & Expressions
Solving Linear Systems by Substitution
CSE 220 – C Programming Expressions.
Lec 3: Data Representation
Equations Quadratic in form factorable equations
Operators and Expressions
EKT 221 : Digital 2 Serial Transfers & Microoperations
Data Types, Identifiers, and Expressions
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Logical Operators & Truth Tables.
Data Types, Identifiers, and Expressions
Computers & Programming Languages
Solve a system of linear equation in two variables
REGISTER TRANSFER LANGUAGE
Associativity and Prescedence
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Queue Applications Lecture 31 Mon, Apr 9, 2007.
Expressions.
Bitwise Operators.
Queue Applications Lecture 31 Tue, Apr 11, 2006.
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Operator Precedence and Associativity
Outline Software Development Activities
Equations Quadratic in form factorable equations
Data Types and Expressions
EECE.2160 ECE Application Programming
Data Types and Expressions
Presentation transcript:

Bit-String Flicking

  Bit strings (binary numbers) are frequently manipulated using logical operators, shifts, and circulates. Mastering this topic is essential for systems programming, programming in assembly language and optimizing code.

A typical use: maintain a set of flags. 10 “options” - “on” or “off” Could use an array of size 10 or could use a single variable (if it is internally stored using at least 10 bits) use 1 bit to record each option saves space cleaner

Logical operators AND(&), OR(|), XOR() and NOT(~) Examine the operand(s) on a bit by bit basis. For example, (10110 AND 01111) has a value of 00110. The AND, OR and XOR are binary operators; the NOT is a unary operator.

Logical Operators p q p AND q p OR q p XOR q NOT p 1

Logical shifts (LSHIFT-x and RSHIFT-x) “ripple” the bit string x positions in the indicated direction. Bits shifted out are lost zeros are shifted in at the other end Circulates (RCIRC-x and LCIRC-x) “ripple” the bit string x positions in the specified direction. As each bit is shifted out one end, it is shifted in at the other end. size of a bit string is fixed If any bit strings are initially of different lengths, all shorter ones are padded with zeros in the left bits until all strings are of the same length

Logical Shifts p LSHIFT-2 p RSHIFT-2 p LCIRC-3 p RCIRC-3 p 01101 10100 00011 01011 10101 10 00 01 1110 1000 0011 0111 1101 1011011 1101100 0010110 1011101 0111011

Order of precedence (from highest to lowest) : NOT; SHIFT and CIRC; XOR; OR. Operators with equal precedence are evaluated left to right;  

Sample Problems Evaluate the following expression:   (RSHIFT-1 (LCIRC-4 (RCIRC-2 01101)))   The expression evaluates as follows: (RSHIFT-1 (LCIRC-4 (RCIRC-2 01101))) = (RSHIFT-1 (LCIRC-4 01011)) = (RSHIFT-1 10101) = 01010

List all possible values of x (5 bits long) that solve the following equation.   (LSHIFT-1 (10110 XOR (RCIRC-3 x) AND 11011)) = 01100 Since x is a string 5 bits long, represent if by abcde. (RCIRC-3 x) is cdeab which, when ANDed with 11011 gives cd0ab. This is XORed to 10110 to yield Cd1Ab (the capital letter is the NOT of its lower case).   Now, if (LSHIFT-1 Cd1Ab) has a value of 01100, we must have: d=0, A=1 (hence a=0), b=0. Thus, the solution must be in the form 00*0*, where * is an “I-don’t-care”. The four possible values of x are: 00000, 00001, 00100 and 00101.

(LC-3 (10110 XOR 11010) AND (RS-1 10111)) = (LCIRC-3 01100 AND 01011) Evaluate the following expression:   ((LCIRC-3 (10110 XOR 11010)) AND (RSHIFT-1 10111)) (LC-3 (10110 XOR 11010) AND (RS-1 10111)) = (LCIRC-3 01100 AND 01011) = (00011 AND 01011) = 00011

Evaluate the following expression: ((RCIRC-14 (LCIRC-23 01101)) |   Evaluate the following expression: ((RCIRC-14 (LCIRC-23 01101)) | (LSHIFT-1 10011) & (RSHIFT-2 10111))   The rules of hierarchy must be followed carefully: A = (RCIRC-14 (LCIRC-23 01101)) = (LCIRC-9 01101) = (LCIRC-4 01101) = 10110 B = (LSHIFT-1 10011) = 00110 C = (RSHIFT-2 10111) = 00101 D = B & C = 00100 final answer = A | D = 10110

(LSHIFT-2 (RCIRC-3 (NOT x)))   Find all possible values of x for which the following expression has a value of 10100. (LSHIFT-2 (RCIRC-3 (NOT x))) Let x=ABCDE and (NOT x)=abcde. Substitute into the expression:   (RCIRC-3 abcde) = cdeab and (LSHIFT-2 cdeab) = eab00. Since eab00 = 10100 the value of (NOT x) is 01**1 (where the * indicates an “I-don’t-care”), and the value of x is 10**0: 10000, 10010, 10100 and 10110.