Binary Which powers of 2 are we adding? Decimal answer 10101

Similar documents
Base Conversion written by Cathy Saxton

Useful Number Systems

Section 1.4 Place Value Systems of Numeration in Other Bases

Binary Numbers. Binary Octal Hexadecimal

Computer Science 281 Binary and Hexadecimal Review

Chapter 7 Lab - Decimal, Binary, Octal, Hexadecimal Numbering Systems

2 Number Systems. Source: Foundations of Computer Science Cengage Learning. Objectives After studying this chapter, the student should be able to:

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

=

CSI 333 Lecture 1 Number Systems

Everything you wanted to know about using Hexadecimal and Octal Numbers in Visual Basic 6

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

COMPSCI 210. Binary Fractions. Agenda & Reading

Unsigned Conversions from Decimal or to Decimal and other Number Systems

Numeration systems. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

Chapter 4: Computer Codes

Positional Numbering System

HOMEWORK # 2 SOLUTIO

1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal:

Number Systems and Radix Conversion

Systems I: Computer Organization and Architecture

THE BINARY NUMBER SYSTEM

Chapter 2. Binary Values and Number Systems

Decimal to Binary Conversion

Lecture 2. Binary and Hexadecimal Numbers

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

Unit 7 The Number System: Multiplying and Dividing Integers

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

NUMBER SYSTEMS. 1.1 Introduction

3. Convert a number from one number system to another

Binary, Hexadecimal, Octal, and BCD Numbers

The Hexadecimal Number System and Memory Addressing

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory.

Digital codes. Resources and methods for learning about these subjects (list a few here, in preparation for your research):

NUMBER SYSTEMS. William Stallings

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Lecture 11: Number Systems

Activity 1: Using base ten blocks to model operations on decimals

The string of digits in the binary number system represents the quantity

Unit 6 Number and Operations in Base Ten: Decimals

Prerequisite knowledge Students should have a good understanding of how our decimal number system works as well as understand place value.

2011, The McGraw-Hill Companies, Inc. Chapter 3

Verilog - Representation of Number Literals

Numbering Systems. InThisAppendix...

CS201: Architecture and Assembly Language

Binary Representation

NUMBER SYSTEMS APPENDIX D. You will learn about the following in this appendix:

plc numbers Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

**Unedited Draft** Arithmetic Revisited Lesson 5: Decimal Fractions or Place Value Extended Part 3: Multiplying Decimals

Number Conversions Dr. Sarita Agarwal (Acharya Narendra Dev College,University of Delhi)

Fractions to decimals

Introduce Decimals with an Art Project Criteria Charts, Rubrics, Standards By Susan Ferdman

A Step towards an Easy Interconversion of Various Number Systems

Unit 1 Number Sense. In this unit, students will study repeating decimals, percents, fractions, decimals, and proportions.

Counting in base 10, 2 and 16

Converting from Fractions to Decimals

Cyber Security Workshop Encryption Reference Manual

Number of bits needed to address hosts 8

Multiplication. Year 1 multiply with concrete objects, arrays and pictorial representations

6 The Hindu-Arabic System (800 BC)

Binary Adders: Half Adders and Full Adders

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

Memory Management Simulation Interactive Lab

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

MULTIPLICATION AND DIVISION OF REAL NUMBERS In this section we will complete the study of the four basic operations with real numbers.

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Chapter 1: Digital Systems and Binary Numbers

20 CODE CHALLENGES. GCSE (9 1) Computer Science GCSE REFORM. February 2015

Part 1 Expressions, Equations, and Inequalities: Simplifying and Solving

1.6 Division of Whole Numbers

Chapter 1. Binary, octal and hexadecimal numbers

IP Subnetting and Related Topics A Tutorial by Chris Uriarte <chrisjur@cju.com> Updated April 2001

Chapter 5 Instructor's Manual

Vieta s Formulas and the Identity Theorem

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Trader s Guide. Updated March 2014

C H A P T E R Regular Expressions regular expression

This explains why the mixed number equivalent to 7/3 is 2 + 1/3, also written 2

Japanese Character Printers EPL2 Programming Manual Addendum

IT:101 Cisco Networking Academy I Subnetting

Subnetting Examples. There are three types of subnetting examples I will show in this document:

Excel: Introduction to Formulas

Mathematical goals. Starting points. Materials required. Time needed

Chapter 5. Binary, octal and hexadecimal numbers

Table 1 below is a complete list of MPTH commands with descriptions. Table 1 : MPTH Commands. Command Name Code Setting Value Description

CPEN Digital Logic Design Binary Systems

Math Circle Beginners Group October 18, 2015

Revision 5 - (Released April 2008) Added further definitions of RFID tag contents and testing requirements for RFID tag read range.

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

The Concept of Present Value

DIVISION OF DECIMALS We then we multiply by the

SUBNETTING SCENARIO S

Grade Level Year Total Points Core Points % At Standard %

2. Setting Up The Charts

Creating a Gradebook in Excel

Integers are positive and negative whole numbers, that is they are; {... 3, 2, 1,0,1,2,3...}. The dots mean they continue in that pattern.

Today s topics. Digital Computers. More on binary. Binary Digits (Bits)

Lab 17: Building a 4-Digit 7-Segment LED Decoder

Streaming Lossless Data Compression Algorithm (SLDC)

Transcription:

1 CS 105 Lab #1 representation of numbers numbers are the dough we use to represent all information inside the computer. The purpose of this lab is to practice with some binary number representations. After finishing this lab, you should feel more comfortable expressing numbers in both decimal (base 10) and binary (base 2). We will also look at some simple properties and shortcuts of binary representation. Part I: to decimal conversion As an example, let s look at the binary number 11010. 1 1 0 1 0 2 4 = 16 2 3 = 8 2 2 = 4 2 1 = 2 2 0 = 1 To determine its value in base 10, all we need to do is add up the powers of 2 wherever we see a 1 in our binary number. In this case we have 16 + 8 + 2 = 26. Practice: Convert each of the following binary numbers into decimal. Which powers of 2 are we adding? Decimal answer 10101 11110 1011 10110 101100 Here is an online tool for Internet Explorer that can help you check your answers: http://cs.furman.edu/digitaldomain/more/binary/uconverter.html If that link does not work, you can try the Web site wolframalpha.com and enter commands such as 1101 from binary to decimal. Part II: Decimal to binary conversion: the Store To convert a number n into binary, pretend you have $n to spend at the binary store. Your strategy is to buy the most valuable gifts you can. The price list at the store is simply the powers of two: 1, 2, 4, 8, 16, 32, 64, etc. Example: Let s say you have $60 to start with. First, buy a $32 item. This will leave you with 60 32 = 28. Next, buy a $16 item. This leaves you with 28 16 = 12. Next, buy an $8 item. Now you have 12 8 = 4. Finally you can buy a $4 item, and all your money is spent.

2 Your cashier receipt shows that you bought items costing: 32 + 16 + 8 + 4. Each of these numbers is a power of 2, so we can fill in the blanks. 1 means you bought that item, and 0 means you didn t. In this case, we did not buy any $2 or $1 item. 1 1 1 1 0 0 2 5 = 32 2 4 = 16 2 3 = 8 2 2 = 4 2 1 = 2 2 0 = 1 Thus, the decimal number 60 is equivalent to the binary 111100. Try these examples. Convert decimal numbers to binary: Decimal What can you buy at the binary store? answer 36 19 25 50 100 Observations Looking at the above examples, let s see if we can detect some patterns. 1. Look at binary representations of the odd numbers we did earlier, such as 19, 25, etc. What do they all have in common? 2. Look at the even numbers like 26, 50 and 100. What do their binary representations have in common? 3. Let s do an experiment. We ll start with the binary string 1101. a. What number does this equal?

3 b. Let s append a 0 onto the end of our original string, to become 11010. What number do we have now? c. Let s append a 1 onto the end of our original string, to become 11011. What number do we have now? d. Let s come up with a general rule. Let s say you ve just written down the binary form of some number x. What will happen to the value of the number if we put a 0 at the end of x? What would happen if we put a 1 at the end? 4. Let s look at binary strings that have all 1 s in them. Determine the values of the following binary numbers: a. 11 b. 111 c. 1111 d. 11111 e. What do all of these numbers (e.g. 1, 11, 111, 1111, 11111, etc.) have in common? Be as specific as you can.

4 Part III: shorthand numbers can be painful to write or type when they get long. For example, when we study colors later on, it turns out that to completely specify a color takes 24 bits! ( bit = binary digit) Here is an example: 100110010011001111111111 There are 2 kinds of shorthand to help us. They are called octal and hexadecimal. means base 8, and 8 is 2 3. Thus, one octal digit can stand for 3 bits. To avoid confusion, octal numbers are sometimes preceded by the digit zero to emphasize that the number is in octal. Thus, 0101 means the 3-digit octal number 101, which happens to equal 65. To experiment with octal numbers, let s play with the online calculator again. Set it up so that it will convert from base 8 to base 2. Ask it to do these conversions, and write down the answers: 4 7 5 475 547 In the examples 475 and 547, how many bits are in our answers? Can you see the individual octal digits? For example, 475 is 4 followed by 7 followed by 5. Now let s try a few more octal-to-binary cases: 6 1 2 612 126 How many bits does it take to represent the octal 612? What about 126? Why do you think there is a difference? Next, set up the online calculator so that it will go the other way: from base 2 to base 8. Ask the calculator to do these conversions:

5 110 110111 010111000 Can you see how the octal shorthands are determined? Explain how it is done, in your own words. adecimal The second type of shorthand is called hexadecimal, or just hex for short. This means base 16, and 16 = 2 4. Thus, each hex digit stands for 4 bits, making hex even more efficient than octal as a shorthand for binary. To avoid confusion, the prefix 0x is sometimes used as an indicator that the number is being written in hexadecimal. Thus, 0x10 means the 2-digit hexadecimal number 10, which happens to equal sixteen, not the number ten or two! Set up the online calculator to go from base 16 to base 2. Ask it to do these conversions: 9 3 93 903 309 Again, note the number of bits in our answers. Now, let s go the other way. Let s ask the online calculator to convert from binary to hexadecimal. Set up the calculator to convert from base 2 to base 16. Ask it to do these conversions. (Note that in some binary strings below, I have inserted a space for readability purposes.) 0101 0011 0011 0101 1001 0000 1001 1001 1100 1001 1100

6 Do the last two results look strange? It turns out that in base 16, we must have 16 different symbols for our digits. The digits 0-9 are already familiar to us, but now we need special symbols to represent digit values 10-15. To fully understand what is going on with hex shorthand, we can ask the online calculator to convert some numbers from decimal to hex. Write the results in the following table: Decimal 9 10 11 12 13 14 15 16 Decimal 30 31 32 33 158 159 160 161 Let s practice a little more using hexadecimal notation that makes use of letters. Work the following problems, and use the online calculator to check your answers. 5. Convert these binary to hexadecimal: a. 101011 (Hint: if the number of bits is not already a multiple of 4, pad with zeros on the left as necessary.) b. 1010 0110 c. 1111 1110 1000 1001 1010 6. Convert these hexadecimal to binary: a. 0x45 b. 0xa1e c. 0x7f