1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations.

Slides:



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

DATA REPRESENTATION CONVERSION.
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
ECE 331 – Digital System Design
1 Number Systems. 2 Numbers Each number system is associated with a base or radix – The decimal number system is said to be of base or radix 10 A number.
Number Systems and Arithmetic
COE 202: Digital Logic Design Number Systems Part 1
Number Systems Lecture 02.
+ CS 325: CS Hardware and Software Organization and Architecture Integers and Arithmetic.
Dr. Bernard Chen Ph.D. University of Central Arkansas
Binary and Hexadecimal Numbers
Number Systems.
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Chapter 1 Basic Principles of Digital Systems. 2 Analog vs. Digital Analog: –A way of representing a physical quantity by a proportional continuous voltage.
Numbering systems.
EKT 121 / 4 ELEKTRONIK DIGIT 1 CHAPTER 1 : INTRODUCTION.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Digital Electronics. Digital circuits work on the basis of a transistor being used as a switch. Consider a light switch, a transistor can be considered.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
ECE 3110: Introduction to Digital Systems Number Systems.
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
CCE-EDUSAT SESSION FOR COMPUTER FUNDAMENTALS Date: Session III Topic: Number Systems Faculty: Anita Kanavalli Department of CSE M S Ramaiah.
Digital Logic Lecture 2 Number Systems
Number Base Conversions
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
June 10, 2002© Howard Huang1 Number systems To get started, we’ll discuss one of the fundamental concepts underlying digital computer design:
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
Orange Coast College Business Division Computer Science Department CS 116- Computer Architecture Logic Design: Part 1.
Chapter 1 Number Systems Digital Electronics. Topics discussed in last lecture Digital systems Advantages of using digital signals over analog. Disadvantages.
CSC 331: DIGITAL LOGIC DESIGN COURSE LECTURER: E. Y. BAAGYERE. CONTACT: LECTURE TIME: 15:40 – 17:45 hrs. VENUE: SP-LAB.
ECE 2110: Introduction to Digital Systems
CSC 3210 Computer Organization and Programming
ECE DIGITAL LOGIC LECTURE 2: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/14/2016.
CS151 Introduction to Digital Design Chapter 1: Digital Systems and Information Lecture 2 1Created by: Ms.Amany AlSaleh.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Number Systems & Binary Arithmetic
Introduction To Number Systems
Digital Design Chapter One Digital Systems and Binary Numbers
Numbering Systems.
Number Systems and Binary Arithmetic
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
CHAPTER 1 : INTRODUCTION
Introduction Molecules: made up of atoms of individual elements.
Number Systems.
COMPUTING FUNDAMENTALS
Number System conversions
Fundamentals & Ethics of Information Systems IS 201
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
University of Gujrat Department of Computer Science
Number Systems and Binary Arithmetic
Digital Electronics & Logic Design
Numbering System TODAY AND TOMORROW 11th Edition
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Numbers and Arithmetic and Logical Operation
Digital Electronics and Microprocessors
Chapter 2: Number Systems
Homework Homework Continue Reading K&R Chapter 2 Questions?
Chapter Four Data Representation in Computers By Bezawit E.
Number Systems Rayat Shikshan Sanstha’s
Number Systems Rayat Shikshan Sanstha’s
Numbers and Arithmetic and Logical Operation
UNIT – 3 & 4. Data Representation and Internal
Presentation transcript:

1 CS103 Guest Lecture Number Systems & Conversion Bitwise Logic Operations

2 Why 1’s and 0’s Transistors are electronic devices used to build computer hardware – Like a switch (2 positions) – Conducting / Non-conducting – Output voltage of a transistor will either be high or low 1’s and 0’s are arbitrary symbols representing high and low voltage outputs. 2 states of the transistor lead to only 2 values in computer hardware Low Voltage 0V -12V High Voltage +5V +12V 1 0 or on off Controlling Input (Gate) Output (Drain) Source The voltage here determines if current can flow between drain and source Schematic Symbol of a Transistor Functional View of a Transistor as a Switch circuit is open (off) – no current can flow circuit is closed (on) – current can flow Circuit Diagram of a Switch

3 POSITIONAL NUMBER SYSTEMS

4 Interpreting Binary Strings Given a string of 1’s and 0’s, you need to know the representation system being used, before you can understand the value of those 1’s and 0’s. Information (value) = Bits + Context (System) = ? ‘A’ ASCII Unsigned Binary system ASCII system Signed System

5 Binary Number System Humans use the decimal number system – Based on number 10 – 10 digits: [0-9] Because computer hardware uses digital signals with 2 states, computers use the binary number system – Based on number 2 – 2 binary digits (a.k.a bits): [0,1]

6 Number Systems Number systems consist of 1.A base (radix) r 2.r coefficients [0 to r-1] Human System: Decimal (Base 10): 0,1,2,3,4,5,6,7,8,9 Computer System: Binary (Base 2): 0,1 Human systems for working with computer systems (shorthand for human to read/write binary) – Octal (Base 8): 0,1,2,3,4,5,6,7 – Hexadecimal (Base 16): 0-9,A,B,C,D,E,F (A thru F = 10 thru 15)

7 Anatomy of a Decimal Number A number consists of a string of explicit coefficients (digits). Each coefficient has an implicit place value which is a power of the base. The value of a decimal number (a string of decimal coefficients) is the sum of each coefficient times it place value radix (base) (934) 10 = (3.52) 10 =

8 Anatomy of a Decimal Number A number consists of a string of explicit coefficients (digits). Each coefficient has an implicit place value which is a power of the base. The value of a decimal number (a string of decimal coefficients) is the sum of each coefficient times it place value Explicit coefficients Implicit place values radix (base) (934) 10 = 9* * *10 0 = 934 (3.52) 10 = 3* * *10 -2 = 3.52

9 Positional Number Systems (Unsigned) A number in base r has place values/weights that are the powers of the base Denote the coefficients as: a i r -1 r -2 r 1 r 0. r 2 r 3 Left-most digit = Most Significant Digit (MSD) Right-most digit = Least Significant Digit (LSD)... a -1 a -2 a 1 a 0 a 2 a 3 N r = Σ i (a i *r i ) = D 10

10 Examples (746) 8 = (1A5) 16 =

11 Examples (746) 8 = 7* * *8 0 = = (1A5) 16 = 1* * *16 0 = =

12 Anatomy of a Binary Number Same as decimal but now the coefficients are 1 and 0 and the place values are the powers of 2 (1011) 2 = 1* * * *2 0 Least Significant Bit (LSB) Most Significant Digit (MSB) coefficients place values = powers of 2 radix (base)

13 Binary Examples (1001.1) 2 = ( ) 2 =

14 Binary Examples (1001.1) 2 = = ( ) 2 = =

15 Powers of = = = = = = = = = = =

16 Practice On Your Own (11010) 2 = 1* * *2 1 = = (26) 10 (6523) 8 = 6* * * *8 0 = = (3411) 10 (AD2) 16 = 10* * *16 0 = = (2770) 10 Decimal equivalent is… … the sum of each coefficient multiplied by its implicit place value (power of the base) = Σ i (a i * r i ) [a i = coefficient, r = base]

17 Shifting in Binary Move bits to the left or right with 0's shoved in one side and dropping bits on the other Useful for multiplying and dividing by power of 2. – Right shift by n-bits = Dividing by 2 n – Left shift by n-bits = Multiplying by 2 n Right Shift by 2 bits: Left Shift by 3 bits: 0’s shifted in… = +12 = +3= +96

18 Bottom-Up Conversion & Shifting X = =

19 Unique Combinations Given n digits of base r, how many unique numbers can be formed? r n – What is the range? [0 to r n -1] r n Main Point: Given n digits of base r, r n unique numbers can be made with the range [0 - (r n -1)] 2-digit, decimal numbers (r=10, n=2) 3-digit, decimal numbers (r=10, n=3) 4-bit, binary numbers (r=2, n=4) 6-bit, binary numbers (r=2, n=6) combinations: combinations: combinations: combinations:

20 CONVERSION FROM DECIMAL TO OTHER BASE

21 Conversion: Base 10 to Base r X 10 = (?) r General Method (base 10 to arbitrary base r) – Division Method for integer portion or number Alternate Method – Left-to-right (greedy) approach (45) 10 = (?) r

22 Division Method Explanation a4a4 a3a3 a2a2 a1a1 a0a = = a a a a a = a a a a a

23 Binary Division Method Example = (??) 2

24 Binary Division Method Example = (??) Keep dividing until you reach 0 rem. = 1 rem. = 0 rem. = 1 MSB LSB = (101101) 2 Remainders form the number in base r (order from bottom up) rem. = 0 rem. = 1

25 Division Method Converts integer portion of a decimal number to base r Informal Algorithm – Repeatedly divide number by r until equal to 0 – Remainders form coefficients of the number base r – Remainder from last division = MSD (most significant digit) = (??) Keep dividing until you reach 0 rem. = 3 rem. = 2 rem. = 1 MSD LSD = (1233) 5 Remainders form the number in base r (order from bottom up)

26 How number conversion works Each time we divide by r, another coefficient “falls out” and all the other place values are reduced by a factor of r = a 4 a 3 a 2 a 1 a = a a a a a = a a a a a = a a a a a Quotient Rem. a a a a = a a a a QuotientRem. More bits may be required for this actual example, but we'll use 5 to illustrate… This is just explanation for what you've learned…Focus on the conversion process outlined earlier

27 How number conversion works Each time we divide by r, another coefficient “falls out” and all the other place values are reduced by a factor of r. a 0 is the remainder D 10 written as coefficients * place values Factor r out of numerator terms with a n-1 – a 1 This is just explanation for what you've learned…Focus on the conversion process outlined earlier

28 Left-To-Right Method An alternative to the division method To convert a decimal number, x, to binary: – Only coefficients of 1 or 0. So simply find place values that add up to the desired values, starting with larger place values and proceeding to smaller values and place a 1 in those place values and 0 in all others = For the place value 32 is too large to include so we include 16. Including 16 means we have to make 9 left over. Include 8 and

29 Left-To-Right Binary Examples = = = =

30 Left-To-Right In Other Bases Can use the left-to-right method to convert a decimal number, x, to any base r: – Use the place values of base r (powers of r). Starting with largest place values, fill in coefficients that sum up to desired decimal value without going over =4B hex

31 SHORTHAND FOR BINARY Hexadecimal and Octal

32 Binary, Octal, and Hexadecimal Octal (base 8 = 2 3 ) 1 Octal digit ( _ ) 8 can represent: 0 – 7 3 bits of binary (_ _ _) 2 can represent: = 0 – 7 1 Octal digit = 3 bits Conclusion… 1 Octal digit = 3 bits Hex (base 16=2 4 ) 1 Hex digit ( _ ) 16 can represent: 0-F (0-15) 4 bits of binary (_ _ _ _) 2 can represent: = Hex digit = 4 bits Conclusion… 1 Hex digit = 4 bits

33 Binary to Octal or Hex Make groups of 3 bits starting from radix point and working outward Add 0’s where necessary Convert each group of 3 to an octal digit Make groups of 4 bits starting from radix point and working outward Add 0’s where necessary Convert each group of 4 to an octal digit E.C EC

34 Octal or Hex to Binary Expand each octal digit to a group of 3 bits Expand each hex digit to a group of 4 bits D

35 LOGIC OPERATIONS

36 Bitwise Logical Operations B1B2F AND B1 B2 Pass Force '0' Z X Y XOR B1 B2 F B1B2F Pass Invert B1B2F Pass Force '1' B1 B2 OR 0 | x = x 1 | x = 1 x | x = x 0 & x = 0 1 & x = x x & x = x 0 ^ x = x 1 ^ x = ~ x x ^ x = 0 XF F = X or ~X

37 Logical Operations Logic operations on numbers means performing the operation on each pair of bits 0xF0 AND 0x3C 0x AND xF0 OR 0x3C 0xFC OR xF0 XOR 0x3C 0xCC XOR NOT 0xAC 0x53 NOT

38 Logical Operations The C language has two types of logic operations – Logical and Bitwise Logical Operators (&&, ||, !) – Operate on the logical value of a FULL variable (char, int, etc.) interpreting that value as either True (non-zero) or False (zero) char x = 1, y = 2, z; z = x && y; – Result is z = 1; Why? Bitwise Logical Operators (&, |, ^, ~) – Operate on the logical value of INDIVIDUAL bits in a variable char x = 1, y = 2, z; z = x & y; – Result is z = 0; Why?

39 Logical Operations Logic operations on numbers means performing the operation on each pair of bits 0x7A AND 0xEC 0x30 0x36 OR 0x91 0xFC 0x3C 0x78 XOR 0x3C 0x78

40 Look Toward LFSR PA One of your next PA's will utilize the bitwise XOR operator and leverage the fact that: – a ^ b ^ a = b Proof:

41 Logical Operations Bitwise logic operations are often used for "bit fiddling" – Change the value of a bit in a register w/o affecting other bits – C operators: & = AND, | = OR, ^ = XOR, ~ = NOT Examples (Assume an 8-bit variable, v) – Clear the LSB to '0' w/o affecting other bits v = v & 0xfe; – Set the MSB to '1' w/o affecting other bits v = v | 0x80; – Flip the LS 4-bits w/o affecting other bits v = v ^ 0x0f; ? v ??????? 7 & _________________ ? v ??????0 ? v ??????? | ? v ??????1 ? v ??????? ^ ? v ??????? Bit #

42 Exercises for Practice Q1-Q15 on the posted worksheet – erSys.pdf erSys.pdf