Homework Hints Algorithms.

Slides:



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

Please turn in your Home-learning, get your notebook and Springboard book, and begin the bell-ringer! Test on Activity 6, 7 and 8 Wednesday (A day) and.
2-1 Chapter 2 - Data Representation Computer Architecture and Organization by M. Murdocca and V. Heuring © 2007 M. Murdocca and V. Heuring Computer Architecture.
Chapter 2: Data Representation
Binary Addition Rules Adding Binary Numbers = = 1
EMB1006 The Binary System There is no 2 Jonathan-Lee Jones.
Data Representation Computer Organization &
Data Representation COE 205
Assembly Language and Computer Architecture Using C++ and Java
Kavita Hatwal Fall The decimal system, also called the base 10 number system is based on ten numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. All the numbers.
Signed Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Chapter Chapter Goals Know the different types of numbers Describe positional notation.
Data Representation ICS 233
Chapter 02 Binary Values and Number Systems Nell Dale & John Lewis.
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.
Data Representation in Computers. Data Representation in Computers/Session 3 / 2 of 33 Number systems  The additive approach – Number earlier consisted.
Scientific Notation Review
Binary and Hexadecimal Numbers
Simple Data Type Representation and conversion of numbers
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Lecture for Week Spring.  Numbers can be represented in many ways. We are familiar with the decimal system since it is most widely used in everyday.
Number Systems Binary and Hexadecimal. Base 2 a.k.a. Binary  Binary works off of base of 2 instead of a base 10 like what we are taught in school 
Data Representation – Binary Numbers
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
Multiplying and Dividing Decimals by 10, 100, and 1,000
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.
Exponents.
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,
5.5 Negative Exponents and Scientific Notation. Negative Exponents Using the quotient rule, But what does x -2 mean?
By Kevin Le. Exponent Laws  There are 3 different exponent laws. -Multiplication Law – You must add the exponents together when you multiply powers with.
Positional Number Systems
Binary Values and Number Systems
Positional Notation 642 in base 10 positional notation is:
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.
Operations on Bits Arithmetic Operations Logic Operations
Number Systems Binary to Decimal Octal to Decimal Hexadecimal to Decimal Binary to Octal Binary to Hexadecimal Two’s Complement.
Dale & Lewis Chapter 2 Binary Numbers and Number Systems.
AEEE2031 Data Representation and Numbering Systems.
1 Review on Number Systems Decimal, Binary, and Hexadecimal.
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
Addition and Substraction
Computer Science Introduction to the Number Base Unit Adapted from Slides by John Owen Computer Science Instructor, Rockport-Fulton High School, Rockport,
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.
1 4. Computer Maths and Logic 4.1 Number Systems.
1 Number Systems Decimal, Binary, and Hexadecimal.
SCIENTIFIC NOTATION RULES. Rules for converting to Scientific Notation One non-zero number before the decimal One digit after the decimal If you are making.
Opener Evaluate when x = 4.. Test Review Simplifying Exponent Rules.
Hexadecimal (base 16) BY MAT D. What is hexadecimal  Hexadecimal is a number system like binary or denary that has 16 characters, the numbers 0-9 and.
Data Representation COE 301 Computer Organization Dr. Muhamed Mudawar
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Starter Using two’s Complement form convert the following from Denary to Binary using 8 bits. Answer on mini whiteboard Using two’s.
Binary Values. Numbers Natural Numbers Zero and any number obtained by repeatedly adding one to it. Examples: 100, 0, 45645, 32 Negative Numbers.
Data Representation COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum.
Data Representation COE 308 Computer Architecture
Data Representation ICS 233
Scientific Notation.
Data Representation.
Digital Systems and Number Systems
SCIENTIFIC NOTATION.
Data Representation COE 301 Computer Organization
Digital Electronics and Microprocessors
Unit 18: Computational Thinking
Binary  Name: Class: .
Data Representation ICS 233
Hexadecimal.
Binary, Hexadecimal, and Base 10.
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Data Representation COE 308 Computer Architecture
Presentation transcript:

Homework Hints Algorithms

Converting Positive Numbers Base 2 to base 16 Base 16 to base 2 Base 16 to base 10 Base 2 to base 10 Base 10 to base 2 Base 10 to base 16

Converting positive numbers: base 2 to base 16 Put the digits into groups of 4 starting at the right If the last group has last than 4 digits, extend it with leading 0s Convert each group of 4 according to the following translation 0000 -> 0, 0001 -> 1, 0010 -> 2, 0011 ->3 0100 -> 4, 0101 -> 5, 0110 -> 6, 0111 -> 7 1000 -> 8, 1001 -> 9, 1010 -> A, 1011 -> B 1100 -> C, 1101 -> D, 1110 -> E, 1111 -> F

Example: 0110010010010012 to base 16 011 0010 0100 1001 3 2 4 9 3249

Converting positive numbers: base 16 to base 2 Convert each digit into a group of 4 according to the following translation 0 -> 0000, 1 -> 0001, 2 -> 0010, 3 -> 0011 4 -> 0100, 5 -> 0101, 6 -> 0110, 7 -> 0111 8 -> 1000, 9 -> 1001, A -> 1010, B -> 1011 C -> 1100, D -> 1101, E -> 1110, F -> 1111

Example: 8EF16 to base 2 8 = 1000 E = 1110 F = 1111 100011101111

Converting positive numbers: base 16 to base 10 Expand the number into its component values: face-value x position value Position value rightmost digit, position value = 160 Moving right to left, the exponent in each position increases by 1 (161, 162, 163, … ) Face value 0 - 9 are their face values A - F are 10 – 15 respectively Convert each exponent to its decimal equivalent Multiply each face-value pair together Add the values together

Example: CAB16 to base 10 C x 162 + A x 161 + B x 160 = 12 x 256 + 10 x 16 + 11 x 1 = 3072 + 160 + 11 = 3243

Converting positive numbers: base 2 to base 10 Expand the number into its component values: face-value x position value Position value rightmost digit, position value = 20 Moving right to left, the exponent in each position increases by 1 (21, 22, 23, … ) Face value 0 = 0, 1 = 1 Eliminate all the 0 terms Simplify each 1x2n to 2n Convert each exponent to its decimal equivalent Add the values together

Example: 1100101010112 to base 10 1x211 + 1x210 + 0x29 + 0x28 + 1x27 + 0x26 + 1x25 + 0x24 + 1x23 + 0x22 + 1x21 + 1x20 = 1x211 + 1x210 + 1x27 + 1x25 + 1x23 + 1x21 + 1x20 = 211 + 210 + 27 + 25 + 23 + 21 + 20 = 2048 + 1024 + 128 + 32 + 8 + 2 + 1 = 3243

Converting positive numbers: base 10 to base 2 Divide the number by 2 Use the remainder as the next number (beginning at the right) If the result is 0 then stop Use the result as the next number and go to step 1

Example: 327 to base 2 327 / 2 = 163 r 1 answer 1

Converting positive numbers: base 10 to base 16 Divide the number by 16 Use the remainder as the next number (beginning at the right) If the remainder is less than 10, use the number directly, else convert it to a letter using 10->A, 11->B, 12->C, 13->D, 14->E, 15->F If the result is 0 then stop Use the result as the next number and go to step 1

Example: 327 to base 16 327 / 16 = 20 r 7 answer 716

Two’s Complement Convert a positive base 10 number to binary two’s complement Convert a negative base 10 number to binary two’s complement Convert a positive base 10 number to hexadecimal two’s complement Convert a negative base 10 number to hexadecimal two’s complement

Convert a positive base 10 number to binary two’s complement Convert the number to base 2 as described on slide 11 Fill in all leading spaces with 0’s

Example: 52 to binary two’s complement Extend to 16-bit field: 0000000000110101

Convert a negative base 10 number to binary two’s complement Convert the positive value of number to binary as described on slide 11 Fill in all leading spaces with 0’s Flip all digits: 0 -> 1, 1 -> 0 Add binary 1 to the number, remembering the following rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10

Example: -52 to binary two’s complement extend to 16 bits 0000000000110101 Flip the bits and add 1 1111111111001010 + 1 1111111111001011

Convert a positive base 10 number to hexadecimal two’s complement Convert the number to base 2 as described on slide 11 Fill in all leading spaces with 0’s Put the digits into groups of 4 starting at the right Convert each group of 4 according to the following translation 0000 -> 0, 0001 -> 1, 0010 -> 2, 0011 ->3 0100 -> 4, 0101 -> 5, 0110 -> 6, 0111 -> 7 1000 -> 8, 1001 -> 9, 1010 -> A, 1011 -> B 1100 -> C, 1101 -> D, 1110 -> E, 1111 -> F

Example: 52 to hexadecimal two’s complement 52/2 = 26 r 1 1 26/2 = 13 r 0 01 13/2 = 6 r 1 101 6/2 = 3 r 0 0101 3/2 = 1 r 1 10101 1/2 = 0 r 1 110101 0000000000110101 0000 0000 0011 0101 003516

Convert a negative base 10 number to binary two’s complement Convert the positive value of number to binary as described on slide 11 Fill in all leading spaces with 0’s Flip all digits: 0 -> 1, 1 -> 0 Add binary 1 to the number, remembering the following rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 Put the digits into groups of 4 starting at the right Convert each group of 4 according to the following translation 0000 -> 0, 0001 -> 1, 0010 -> 2, 0011 ->3 0100 -> 4, 0101 -> 5, 0110 -> 6, 0111 -> 7 1000 -> 8, 1001 -> 9, 1010 -> A, 1011 -> B 1100 -> C, 1101 -> D, 1110 -> E, 1111 -> F

Example: -52 to binary two’s complement 0000000000110101 1111111111001010 + 1 1111111111001011 1111 1111 1100 1011 FFCB16

Two’s Complement Operations Binary addition Binary subtraction Binary comparison Hexadecimal addition Hexadecimal subtraction Hexadecimal comparison

Binary addition Add the two numbers If the carry into the leftmost digit is not the same as the carry out, define it as an overflow

Example 00000000101110102 +00000000101010112 00000001011001012

Binary subtraction Convert the second number into it’s negative by Flipping each bit (0->1, 1->0) Add binary 1 to the number, remembering the following rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 Add the two numbers If the carry into the leftmost digit is not the same as the carry out, define it as an overflow and stop

Example 00000000101110102 - 00000000101010112 negate 00000000101010112 -> 1111111101010100 + 1 1111111101010101 +11111111010101012 00000000000011112

Binary comparison Subtract the two numbers as described in slide 27 If result is positive (first bit 0), first number is greater If result is negative (first bit 0 and not all others are 0), first number is smaller If result is zero, numbers are equal

Example 00000000101110102 - 00000000101010112 00000000000011112 First number is greater than the second

Hexadecimal addition Convert both numbers into binary as described in slide 5 Add the two numbers If the carry into the leftmost digit is not the same as the carry out, define it as an overflow and stop Put the digits into groups of 4 Convert each group of 4 according to the following translation 0000 -> 0, 0001 -> 1, 0010 -> 2, 0011 ->3 0100 -> 4, 0101 -> 5, 0110 -> 6, 0111 -> 7 1000 -> 8, 1001 -> 9, 1010 -> A, 1011 -> B 1100 -> C, 1101 -> D, 1110 -> E, 1111 -> F

Example: BA16 + AB16 BA16 AB16 1011 1010 1010 1011 0000000010111010 0000000010101011 0000000010111010 +0000000010101011 0000000101100101 0000 0001 0110 0101 016516

Alternative algorithm: hexadecimal addition table 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E

Example: BA16 + AB16 (1) BA16 +AB16 ------------ 516 16516

Hexadecimal subtraction Convert both numbers into binary as described in slide 5 Convert the second number into it’s negative by Flipping each bit (0->1, 1->0) Add binary 1 to the number, remembering the following rules: 0+0=0, 0+1=1, 1+0=1, 1+1=10 Add the two numbers If the carry into the leftmost digit is not the same as the carry out, define it as an overflow

Example: BA16 - AB16 BA16 AB16 1011 1010 1010 1011 0000000010111010 0000000010101011 00000000101110102 - 00000000101010112 negate 00000000101010112 -> 1111111101010100 + 1 1111111101010101 +11111111010101012 00000000000011112 0000 0000 0000 11112 000F16

Alternative algorithm: hexadecimal subtraction table borrow not needed borrow needed 1 2 3 4 5 6 7 8 9 A B C D E F

Example: BA16 - AB16 A B 1A16 - A B16 ------------ F16