Binary & Hex Review.

Slides:



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

Representing Numbers: Integers
Number Systems. 2 The total number of allowable symbols in a number system is called the radix or base of the system. Decimal Numbers: radix = 10 (symbols:
Signed Numbers.
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
IT Systems Number Operations EN230-1 Justin Champion C208 –
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
Two’s Complement 1.As an action: (Assume the starting value is 1011) 1.Flip the bits from the starting value => Add one to get the answer.
Computer Systems 1 Fundamentals of Computing
Binary, Decimal, & Hexadecimal Numbers
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
Binary Representation - Shortcuts n Negation x + x = 1111…1111 two = -1 (in 2’s complement) Therefore, -x = x + 1 n Sign Extension o Positive numbers :
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Numbering systems.
Lecture 1. Number Systems Prof. Taeweon Suh Computer Science Education Korea University ECM585 Special Topics in Computer Design.
Number Systems Part 2 Numerical Overflow Right and Left Shifts Storage Methods Subtraction Ranges.
Numeration Systems Introduction to Binary, Octal, and Hexadecimal.
Computer System & Binary Review. Memory Model What memory is supposed to look like.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Number Systems. Today Decimal Hexadecimal Binary –Unsigned Binary –1’s Complement Binary –2’s Complement Binary.
Lecture 4 Last Lecture –Positional Numbering Systems –Converting Between Bases Today’s Topics –Signed Integer Representation Signed magnitude One’s complement.
Chapter 2 Binary Values and Number Systems. 2 2 Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645,
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 2 Binary Values and Number Systems. The number 943 is an example of a number written in positional notation. The relative positions of the digits.
Computer Math CPS120: Lecture 3. Binary computers have storage units called binary digits or bits: Low Voltage = 0 High Voltage = 1 all bits have 0 or.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
Data Representation Bits, Bytes, Binary, Hexadecimal.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Binary Decimal Hexadecimal
Integer Operations Computer Organization and Assembly Language: Module 5.
{ Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Computer Math CPS120 Introduction to Computer Science Lecture 7.
Number Systems Part 2. Counting in Binary DecimalBinary
Number Systems & Binary How to count. How do we represent numbers? Early systems: – Actual count : ||||| = 5 – Roman numers : XI = 11 Hard to do math:
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.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Number systems. Binary system. Bits and bytes. Modern computers “speak” in a digital language composed of 2 digits. The machine language of modern computers.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Data Representation COE 308 Computer Architecture
Cosc 2150: Computer Organization
Binary & Hex Review.
Data Representation.
Data Representation – numbers Binary conversion Hexadecimal Negative numbers Binary addition Binary shifts.
Chapter 4 Operations on Bits.
Consider this number: , Ones (7 ones) Tens (no tens)
Discrete Mathematics Numbering System.
3.1 Denary, Binary and Hexadecimal Number Systems
COMP211 Computer Logic Design Lecture 1. Number Systems
CSE 102 Introduction to Computer Engineering
Number Systems Lab session 1 Xuan Guo.
Number Systems & Binary
David Kauchak CS 52 – Spring 2016
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSC 370 (Blum)
Fundamentals of Data Representation
Hexadecimal Binary Made Easier.
Data Representation – Numbers
Unit 18: Computational Thinking
Number Representation
Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
Number Systems.
Chapter Four Data Representation in Computers By Bezawit E.
Binary System.
Binary Numbers Material on Data Representation can be found in Chapter 2 of Computer Architecture (Nicholas Carter) CSIT 301 (Blum)
UNIT – 3 & 4. Data Representation and Internal
OBJECTIVES After reading this chapter, the reader should be able to :
Two’s Complement & Binary Arithmetic
Presentation transcript:

Binary & Hex Review

Bits & Bytes

Bits And Bit Patterns N bits gives 2N possible patterns 2 bits = 4 patterns 3 bits = 8 patterns

Bytes Smallest usable chunk of memory: byte : 8 bits Special names for large collections of bytes: Name Number of Bytes power of 2 byte 1 20 kilobyte (KB) 1024 210 megabyte (MB) 1,048,576 220 gigabyte (GB) 1,073,741,824 230 terabyte (TB) 1,099,511,627,776 240

Metric Units Standard metric units

Explaining Size 2TB Drive:

Bi units Metric prefixes May refer to powers of 2 or 10 Roughly equivalent GB GiB 109 = 1000000000 ~ 1073741824 = 230

Bi units Memory measured in powers of 2 Network / Processor in powers of 10 Disk Manufactures powers of 10 OS powers of 2 2 TB = 2 * 1012 2 * 1012 / 240 = 1.819 GiB

This Class Unless stated otherwise, assume all measurements are powers of 2

Powers of 2 How many bytes is 16GB?

Powers of 2 How many bytes is 16GB? = 16 * 230 = 24 * 230 = 234

Unsigned Binary

Bases Place based number representations: 1 2 5 9 1 ten thousands 104 103 hundreds 102 tens 101 ones 100 1 2 5 9 thirty-twos 25 sixteens 24 eights 23 fours 22 twos 21 ones 20 1

Specifying Base Specify base as subscript: 610 = 1102

Binary Number Interpretation Table Method: 64 + 32 + 8 + 1 = 105 011010012 = 10510 128 64 32 16 8 4 2 1

Leading 0's Leading 0's do not matter: 101 = 0101 = 00000101 Byte : fundamental storage unit : 8 bits Often write binary numbers in multiples 8 bits 128 64 32 16 8 4 2 1

Conversion With Division/ Multiplication Binary works in powers of 2 Multiplying/dividing by 2 shifts digits

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001 13 ÷ 2 6 1001 6 ÷ 2 3 01001 3 ÷ 2 101001 1 ÷ 2 1101001

Decimal -> Binary with Division Step 1: Start with a blank answer and the number your are converting Step 2: Divide your number by 2 to make a quotient and a remainder Step 3: Place your remainder on the left side of your answer Step 4: If your quotient is 0, you are done Otherwise, make the quotient your new number and go back to step 2 Convert 105 to binary:  Number ÷ 2 Q R Answer 105 ÷ 2 52 1 52 ÷ 2 26 01 26 ÷ 2 13 001 13 ÷ 2 6 1001 6 ÷ 2 3 01001 3 ÷ 2 101001 1 ÷ 2 1101001 128 64 32 16 8 4 2 1 = 105

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 0 * 2

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 0 * 2 + 1

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 1 * 2

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 1 * 2 + 1

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 3 * 2

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 3 * 2 + 0

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 6

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 6 6 * 2

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 6 _ 6 * 2 + 1

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 6 _ 13

Binary -> Decimal with Multiplication Step 1: Start with the number your are converting and the answer of 0 Step 2: Multiply your answer by 2 Step 3: Remove the leftmost digit of number and add it to your answer Step 4: If number has no more digits, you are done Otherwise, go back to step 2 Convert 11012 to decimal:  Number Answer 1101 101 1 01 3 6 _ 13 128 64 32 16 8 4 2 1 = 13

Unsigned Binary Math

Adding Adding base 2: 1 1 = 1 2 = 10 = keep 0 and carry 1 1 = 1 2 = 10 = keep 0 and carry 1 3 = 11 = keep 1 carry 1 1

Adding Adding base 2: 1 7 5 12 1 = 1 2 = 10 = keep 0 and carry 1 1 = 1 2 = 10 = keep 0 and carry 1 3 = 11 = keep 1 carry 1 7 5 12 1

Overflow What is 1111 + 0001? 1

Overflow What is 1111 + 0001? Overflow: number gets too big to hold in the digits we have 1

Signed Binary

Sign Magnitude?? - / + are two choices Ex: + 5 - 5 sign 4 2 1 sign 4 2 Use a bit value to represent sign Ex: + 5 - 5 sign 4 2 1 sign 4 2 1

Sign Magnitude?? Would need new math algorithm… 1 -3 1

2’s complement 2's Complement System: First bit indicates sign: 0 : Positive #: works like normal What is: 00110 Bit Values: 4+2 Value: 6

2’s complement 2's Complement System: First bit indicates sign: 1 : Negative #: defined as indicated value – 2n where n is number of bits What is: 11010 Bit Values: 16 + 8 + 2 = 26 2n : 25 = 32 Value: 26 – 32 = -6

2’s complement negation To negate a number, reverse bits and add 1 What is -3 as 4-bit 2's complement number?: 0011 start with 3 1100 reverse 1 + 1 1101 -3 in two's complement Check: 1101 = 8 + 4 + 1 = 13 2n = 24 = 16 13 – 16 = -3

2’s complement negation To negate a number, reverse bits and add 1 What is 1101 as a 4-bit 2’s complement number? 1101 start with negative pattern 0010 reverse 2 interpret 3 add one 1101 negated is 3, so it must be -3

More Examples What are? 1 1 1

More Examples What are? 1 1 1 Starts with 0 = normal: 4 + 2 + 1 7

More Examples What are? 4 + 2 + 1 7 1 -1 1 1 1 1 1 1 1 Starts with 0 = normal: 4 + 2 + 1 7 Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 1 -1 1

More Examples What are? 4 + 2 + 1 7 1 -1 8 -8 1 1 1 1 1 1 1 1 1 Starts with 0 = normal: 4 + 2 + 1 7 Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 1 -1 Starts with 1 = negative: Flip Bits Add one: Read number, make negative: 8 -8 1 1 1

Range 2's complement uses half of range for negative, half for 0/positive 4 bits: 24 = 16 values Unsigned 0 to 15 2's Complement -8 to 7

4 bits Biggest positive: 7 -1 : Lowest negative: -8 1 1 Flip (0) 1 1 1 Flip (0) +1 = 1 1 Flip (7) +1 = 8

8 bits Biggest positive: 127 -1 : Lowest negative: -128 1 1 Flip (0) 1 1 1 Flip (0) +1 = 1 1 Flip (127) +1 = 128

2’s complement addition Standard addition algorithm works fine: 1 + -3: 1 -3 1

2’s complement addition Standard addition algorithm works fine: 1 + -3: 1 -3 -2 1 ??? 110 Reverse Bits 001 Interpret 1 Add One 2 Value -2

2’s complement 2 + 4 = 1

2’s complement 2 + 4 = 6 Success – answer fits in four bits Ignore extra carry 1

2’s complement -3 + -2 = 1 3 0011 Reverse Bits 1100 Add one 1101 2 0010 Reverse Bits 1101 Add one 1110 -3 + -2 = 1

2’s complement ??? 1011 Reverse Bits 0100 Add one 0101 Bit Values 1 + 4 Value -5 -3 + -2 = -5 Success – answer fits in four bits Ignore extra carry 1

2’s complement 4 + 6 = 1

2’s complement 4 + 6 = -6!?!?! Overflowed the 4 bits! 1 ??? 1010 Reverse Bits 0101 Add one 0110 Bit Values 2 + 4 Value -6 4 + 6 = -6!?!?! Overflowed the 4 bits! 1

2’s complement -4 + -6 = 1 4 0100 Reverse Bits 1011 Add one 1100 6 0110 Reverse Bits 1001 Add one 1010 1

2’s complement -4 + -6 = 6??? Overflowed the 4 bits! 1

Overflow Big + numbers and Low – numbers can wrap!

2’s complement Final column carry out and in are == : OK Final column carry out and in are != : Overflow 1

Hexadecimal

Hexdecimal Base 16 Each column is a power of 16: = 4096 * 2 + 256 * 0 + 16 * 5 + 1 * 9 = 8192 + 80 + 9 205916 = 828110 4096’s 163 256’s 162 16’s 161 1’s 160 2 5 9

13? How do we represent 13??? 4096’s 163 256’s 162 16’s 161 1’s 160

13? How do we represent 13??? A-F = 10-15 4096’s 256’s 16’s 1’s 163 162 16’s 161 1’s 160

Hex Numbers 1A316 = 1 * 256 + 10 * 16 + 3 * 1 = 256 + 160 + 3 = 41910 4096 256 16 1 A 3

Decimal   Hex Division Methods: ÷ 16 7 12 (C) C7 1C7 Current Value Quotient Remainder 455 ÷ 16 28 7 1 12 (C) C7 1C7

Hex Hexdecimal = base 16 4 bits = 1 hex digit

Summary Hex is a bridge: Easier for us Still just binary for computers System Base Symbols Used by humans? Used in computers? Decimal 10 0, 1, … 9 Yes No Binary 2 0, 1 Hex 16 0-9ABCDEF No, but better than binary No, but easily translates to binary