Bitwise Operators CS163 Fall 2018.

Slides:



Advertisements
Similar presentations
Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana.
Advertisements

How to Convert Decimal Numbers to Binary EXAMPLES.
7-5 Microoperation An elementary operations performed on data stored in registers or in memory. Transfer Arithmetic Logic: perform bit manipulation on.
Senem Kumova Metin CHAPTER 7 Bitwise Operators and Enumeration Types.
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
 | bit OR & bit AND ~ bit NOT ^ bit EXLUSIVE OR (XOR) > bit RIGHT SHIFT.
Binary & Decimal numbers = 3* * *10 + 5*1 = 3* * * *10 0 Decimal system: Ten digits: 0,1,2,3,…,9 Example:
Review Two’s complement
CS 3850 Lecture 5 Operators. 5.1 Binary Arithmetic Operators Binary arithmetic operators operate on two operands. Register and net (wire) operands are.
C expressions (Reek, Ch. 5) 1CS 3090: Safety Critical Programming in C.
 Binary Binary  Binary Number System Binary Number System  Binary to Decimal Binary to Decimal  Decimal to Binary Decimal to Binary  Octal and Hexadecimal.
They are the same as registers since they store binary numbers. Called shifting registers since they shift (left or right) the binary number stored in.
Converting binary to decimal decimal to binary
Convert Decimal to Floating point number [IEEE 754]
Number Systems.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To be able to use the bitwise logical operators in programs ❏ To be able to use.
PYTHON PROGRAMMING Week 14 – Tuesday. STARTER You need to find out the average of a set of exam marks for a class. You don’t know how many marks there.
What is the decimal representation of …? Hit “enter”
1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.
Chapter 18 – Miscellaneous Topics. Multiple File Programs u Makes possible to accommodate many programmers working on same project u More efficient to.
Number Systems and Number Representation Jennifer Rexford 1.
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
PERCENT – Decimal to percent Percent means “how many out of 100”. Think of your GRADE !!! So if you get a 90% on a test, it means you got 90 out of 100.
Bitwise operators. Representing integers We typically think in terms of decimal (base 10) numbers.  Why?  A decimal (or base 10) number consists of.
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.
Bitwise Operators in C. Bitwise operators are used to manipulate one or more bits from integral operands like char, int, short, long.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
MIPS Logic & Shift. Bitwise Logic Bitwise operations : logical operations applied to each bit Bitwise OR:
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
Floating Point in Binary 1.Place Value Chart:
Module 5 JavaScript Operators. CS346 Javascript-52 Examples  JS-5 Examples.
Arithmetic Operations
20. LOW-LEVEL PROGRAMMING. Bitwise Shift Operators The bitwise shift operators are: > right shift The expression i
Assembly 05. Outline Bit mapping Boolean logic (review) Bitwise logic Bit masking Bit shifting Lookup table 1.
1 Sec (2.4) Arithmetic / logic instruction:. 2 Logical operations: Ex: XOR OR AND
Bit Manipulation in 'C' 'C' bit operators
Binary Numbers Practice.
CompSci From bits to bytes to ints  At some level everything is stored as either a zero or a one  A bit is a binary digit a byte is a binary.
Operator Kinds of Operator Precedence of Operator Type Casting.
ARM Bitwise Logic. Bitwise Logic Bitwise operations : Work on patterns of bits, not values represented by those bits.
Binary Numbers. Decimal vs Binary = 1001 = 101 = 10 1 = on = 0 = off = On and off.
♣Multiplying Decimals♣
Binary & Decimal numbers
Chapter 4 Operations on Bits.
Week 3 - Friday CS222.
Boolean Algebra, Bitwise Operations
“Take the top #, Divide by the bottom #!”
COUNTING IN BINARY Binary weightings 0 x x x x 8
Binary Addition & Subtraction
Introduction to Programming and the C Language
Chapter 14 Bitwise Operators Objectives
REGISTER TRANSFER LANGUAGE
Creating Subnets – Network Requirements
The University of Adelaide, School of Computer Science
CS-401 Computer Architecture & Assembly Language Programming
Numbers and Arithmetic and Logical Operation
From the ASCII table… Symbol Decimal Binary A B 66
How is 0.41  10 related to 0.41  100?.
The University of Adelaide, School of Computer Science
CS 206D Computer Organization
COUNTING IN BINARY Binary weightings 0 x x x x 8
ARM Bitwise Logic.
Bitwise Operators.
Bitwise operators.
Numbers and Arithmetic and Logical Operation
Fractions, Decimals, Percents
GCSE COMPUTER SCIENCE Topic 3 - Data 3.3 Logical and Arithmetic Shifts.
Bit Manipulations CS212.
Dr. Clincy Professor of CS
Presentation transcript:

Bitwise Operators CS163 Fall 2018

Java Bitwise Operators Java has six bitwise operators: Symbol Operator & Bitwise AND | Bitwise OR ^ Bitwise XOR ~ Bitwise NOT << LEFT SHIFT >> RIGHT SHIFT CS 160, Spring Semester 2014

Java AND and OR AND operator (&) OR operator (|) A B A & B 1 A B A | B 1 A B A | B 1 CS 160, Spring Semester 2014

Java XOR and NOT XOR operator (^) NOT operator (~) A B A ^ B 1 A ~A 1 1 A ~A 1 CS 160, Spring Semester 2014

Binary to Decimal Decimal Binary 0000b 8 1000b 1 0001b 9 1001b 2 0010b 0000b 8 1000b 1 0001b 9 1001b 2 0010b 10 1010b 3 0011b 11 1011b 4 0100b 12 1100b 5 0101b 13 1101b 6 0110b 14 1110b 7 0111b 15 1111b CS 160, Spring Semester 2014

Binary to Decimal 0-9 are used for decimal numbers (base-10): 149 = 1*102 + 4*101 + 9*100 0-1 are used for binary numbers (base-2): 1010b = 1*23 + 0*22 + 1*21 + *20 = 8 + 2 = 10 Example: 10111b in decimal? 1*24 + 0*23 + 1*22 + 1*21 + 1*21 = 16 + 4 + 2 + 1 = 23 What is 14 in binary? 8 + 4 + 2 = 1*23 + 1*22 + 1*21 + 0*20 = 1110b CS 160, Spring Semester 2014

Bitwise Operator Examples 4-bit numbers: 6 & 5 = 0110b & 0101b = 0100b = 4 6 | 5 = 0110b | 0101b = 0111b = 7 6 ^ 5 = 0110b ^ 0101b = 0011b = 3 ~6 = ~0110b = 1001b = 9 8-bit numbers: 6 << 3 = 00000110b << 3 = 00110000b = 48 (6 * 8) 48 >> 4 = 00110000b >> 4 = 00000011b = 3 (48 / 16) CS 160, Spring Semester 2014

Masking Operations Clearing bits: Setting bits: x = 00101001b = 41 want to clear top 4-bits x = x & 00001111b = x & 15 = 00001001b = 9 Setting bits: want to set bottom 4-bits x = x | 00001111b = x | 15 = 00101111b = 47 CS 160, Spring Semester 2014