Data Representation. What is a number? Decimal Representation. Interpreting bits to give them meaning. Part 1: Numbers. six seis



Similar documents
Computer Science 281 Binary and Hexadecimal Review

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

Section 1.4 Place Value Systems of Numeration in Other Bases

=

Base Conversion written by Cathy Saxton

Lecture 11: Number Systems

Decimal to Binary Conversion

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

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

Useful Number Systems

Lecture 2. Binary and Hexadecimal Numbers

Binary Representation

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

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

Positional Numbering System

Counting in base 10, 2 and 16

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

NUMBER SYSTEMS. William Stallings

Chapter 2. Binary Values and Number Systems

Unsigned Conversions from Decimal or to Decimal and other Number Systems

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

Chapter 4: Computer Codes

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

Number Systems and Radix Conversion

Binary Numbers. Binary Octal Hexadecimal

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

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

The Hexadecimal Number System and Memory Addressing

Binary, Hexadecimal, Octal, and BCD Numbers

Number Systems. Introduction / Number Systems

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

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

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

Decimal Number (base 10) Binary Number (base 2)

The Answer to the 14 Most Frequently Asked Modbus Questions

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

PROGRAMMABLE LOGIC CONTROLLERS Unit code: A/601/1625 QCF level: 4 Credit value: 15 TUTORIAL OUTCOME 2 Part 1

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

CPEN Digital Logic Design Binary Systems

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

Binary Adders: Half Adders and Full Adders

3. Convert a number from one number system to another

Memory is implemented as an array of electronic switches

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

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

Chapter 1: Digital Systems and Binary Numbers

4.3 TABLE 3 TABLE five

Systems I: Computer Organization and Architecture

Digital circuits make up all computers and computer systems. The operation of digital circuits is based on

Previously, you learned the names of the parts of a multiplication problem. 1. a. 6 2 = 12 6 and 2 are the. b. 12 is the

Cyber Security Workshop Encryption Reference Manual

BINARY CODED DECIMAL: B.C.D.

COMPSCI 210. Binary Fractions. Agenda & Reading

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

Basics of Digital Recording

Tristan s Guide to: Solving Series Circuits. Version: 1.0 Written in Written By: Tristan Miller Tristan@CatherineNorth.com

CS201: Architecture and Assembly Language

Number of bits needed to address hosts 8

THE BINARY NUMBER SYSTEM

Zeros, Ones, and the Morse Code

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Number Representation

NUMBER SYSTEMS. 1.1 Introduction

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

Figure 8-1 Four Possible Results of Adding Two Bits

Lab#2: IP Addressing and Subnetting

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

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

Math Circle Beginners Group October 18, 2015

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Grade 6 Math Circles. Binary and Beyond

Digital Design. Assoc. Prof. Dr. Berna Örs Yalçın

Activity 6.7.4: IPv4 Address Subnetting Part 2

2.3 IPv4 Address Subnetting Part 2

IBM Emulation Mode Printer Commands

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

Electronics Merit Badge Class 3. 1/30/2014 Electronics Merit Badge Class 3 1

INTRODUCTION TO FRACTIONS

Solution for Homework 2

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

Lesson Plan. Course Title: Computer Maintenance Session Title: Numbering Systems

Technical Information. Digital Signals. 1 bit. Part 1 Fundamentals

1. The Fly In The Ointment

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

IPv6 Addressing. How is an IPv6 address represented. Classifications of IPv6 addresses Reserved Multicast addresses. represented in Hexadecimal

A PRACTICAL GUIDE TO db CALCULATIONS

FORDHAM UNIVERSITY CISC Dept. of Computer and Info. Science Spring, Lab 2. The Full-Adder

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

Storing Measurement Data

Experiment 4 ~ Resistors in Series & Parallel

HOMEWORK # 2 SOLUTIO

Numbering Systems. InThisAppendix...

A Step towards an Easy Interconversion of Various Number Systems

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

Light Bulbs in Parallel Circuits

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Solutions to Bulb questions

Digital to Analog and Analog to Digital Conversion

Transcription:

Data Representation Interpreting bits to give them meaning Part 1: Numbers Notes for CSC 100 - The Beauty and Joy of Computing The University of North Carolina at Greensboro What is a number? Question: You've been working with numbers (almost) all your life - what are they? Example: What is the number 6? 6 six seis 110 2 Decimal Representation Most common written representation of numbers is "decimal notation": 10 4 (10000) 10 3 (1000) 51862 10 2 (100) 10 1 (10) 10 0 (1) "Representation" is the converse of "Abstraction" Makes abstractions concrete Question: Why powers of ten? Equivalently, why are there 10 different digits?

Decimal Representation How can we mathematically extract digits? 51862 Divide by 10: Quotient gives all but last digit Remainder gives last digit Using the "div" block from Lab 3 Stamping out decimal representation Extending Lab 3 solution to stamp out all digits (not just 2): Now let's see this in action... Binary Representation The powers used in the representation (also, number of different "digits") is called the base. "Decimal" is base 10 "Binary" is base 2 This number is written in binary 1 0 0 1 1 Instead of "digits" have "bits" 2 4 (16) 2 3 (8) 2 2 (4) 2 1 (2) 2 0 (1) Numbers below the dashed line are all written in decimal (because they're for our benefit). 1 * 2 4 + 0 * 2 3 + 0 * 2 2 + 1 * 2 1 + 1 * 2 0 = 16 + 2 + 1 = 19

Converting decimal to binary Just like the BYOB code, we keep dividing by the base (2), recording remainders and keeping quotients. First bit found is last bit in binary representation. Using subscripts to denote base: 43 10 = 101011 2 Converting decimal to binary Just like the BYOB code, we keep dividing by the base (2), recording remainders and keeping quotients. Practice problems: 1 10 = 2 6 10 = 2 8 10 = 2 12 10 = 2 23 10 = 2 31 10 = 2 Using subscripts to denote base: 43 10 = 101011 2 Converting binary to decimal Keep a position and a value, and at each step move position to right, multiply value by 2 and add the new bit. Some terminology: Leftmost bit is "most significant bit" or "msb" Rightmost bit is "least significant bit" or "lsb" So 101101 2 = 45 10

Converting binary to decimal Keep a position and a value, and at each step move position to right, multiply value by 2 and add the new bit. Practice problems: 11 2 = 10 1001 2 = 10 11011 2 = 10 10001 2 = 10 11111 2 = 10 101011 2 = 10 So 101101 2 = 45 10 Counting in binary without converting Picture an odometer with only two values, 0 and 1 When any wheel goes from 1 to 0, turn the one to the left Why binary? In electronics, you can measure voltages on wires Consider 8 wires Each with at either 0 volts or 5 volts Interpreting 0V as 0, and 5V as 1, get: 00101011 2 (= 43 10 ) Voltages can turn on/off switches to create logic circuits

Hexadecimal - another useful base Hexadecimal is base 16. How do we get 16 different digits? Use letters! Hexadecimal digits (or "hex digits" for short): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Counting - now our odometer has 16 digits: Hexadecimal/Decimal Conversions Conversion process is like binary, but base is 16 Problem 1: Convert 423 10 to hexadecimal: 423/16 = quotient 26, remainder 7 (=7 16 ) 26/16 = quotient 1, remainder 10 (=A 16 ) 1/16 = quotient 0, remainder 1 (=1 16 ) Reading digits bottom-up: 423 10 = 1A7 16 Problem 2: Convert 9C3 16 to decimal: Start with first digit, 9 9*16 + 12 = 156 156*16 + 3 = 2499 Therefore, 9C3 16 = 2499 10 0 16 = 0 10 1 16 = 1 10 2 16 = 2 10 3 16 = 3 10 4 16 = 4 10 5 16 = 5 10 6 16 = 6 10 7 16 = 7 10 8 16 = 8 10 9 16 = 9 10 A 16 = 10 10 B 16 = 11 10 C 16 = 12 10 D 16 = 13 10 E 16 = 14 10 F 16 = 15 10 Hexadecimal/Decimal Conversions Conversion process is like binary, but base is 16 Problem 1: Convert 423 10 to hexadecimal: 423/16 = quotient 26, remainder 7 (=7 16 ) 26/16 = quotient 1, remainder 10 (=A 16 ) 1/16 = quotient 0, remainder 1 (=1 16 ) 0 16 = 0 10 1 16 = 1 10 2 16 = 2 10 3 16 = 3 10 4 16 = 4 10 5 16 = 5 10 Reading digits bottom-up: 423 10 = 1A7 16 Problem 2: Convert 9C3 16 to decimal: Start with first digit, 9 9*16 + 12 = 156 156*16 + 3 = 2499 Therefore, 9C3 16 = 2499 10 Your turn! Convert: 103 10 = 16 247 10 = 16 952 10 = 16 3C 16 = 10 B9 16 = 10 357 16 = 10 6 16 = 6 10 7 16 = 7 10 8 16 = 8 10 9 16 = 9 10 A 16 = 10 10 B 16 = 11 10 C 16 = 12 10 D 16 = 13 10 E 16 = 14 10 F 16 = 15 10

Hexadecimal/Binary Conversions Exactly 16 hex digits, and exactly 16 4-bit binary numbers Converting between hex and binary is easy - 4 bits at a time: Problem 1: Convert 01110100110 2 to hexadecimal 011 1010 0110 3 A 6 Answer: 3A6 16 Problem 2: Convert D49 16 to binary D 4 9 1101 0100 1001 Answer: 110101001001 2 0 16 = 0000 2 1 16 = 0001 2 2 16 = 0010 2 3 16 = 0011 2 4 16 = 0100 2 5 16 = 0101 2 6 16 = 0110 2 7 16 = 0111 2 8 16 = 1000 2 9 16 = 1001 2 A 16 = 1010 2 B 16 = 1011 2 C 16 = 1100 2 D 16 = 1101 2 E 16 = 1110 2 F 16 = 1111 2 Hexadecimal/Binary Conversions Exactly 16 hex digits, and exactly 16 4-bit binary numbers Converting between hex and binary is easy - 4 bits at a time: Problem 1: Convert 01110100110 2 to hexadecimal 011 1010 0110 3 A 6 Answer: 3A6 16 D 1101 Problem 2: Convert D49 16 to binary 4 0100 9 1001 Answer: 110101001001 2 Your turn! Convert: 12 16 B1 16 FF 16 48 16 1010101 2 10100110 2 00010100 2 01101110 2 0 16 = 0000 2 1 16 = 0001 2 2 16 = 0010 2 3 16 = 0011 2 4 16 = 0100 2 5 16 = 0101 2 6 16 = 0110 2 7 16 = 0111 2 8 16 = 1000 2 9 16 = 1001 2 A 16 = 1010 2 B 16 = 1011 2 C 16 = 1100 2 D 16 = 1101 2 E 16 = 1110 2 F 16 = 1111 2 Use of hexadecimal in file dumps Binary is a very long format (8 bits per byte), but often data files only make sense as binary data. Hexadecimal is great for this - simple one-to-one correspondence with binary, and more compact. Sample "file dump": 0000000: ffd8 ffe1 35fe 4578 6966 0000 4949 2a00...5.Exif..II*. 0000010: 0800 0000 0b00 0e01 0200 2000 0000 9200...... 0000020: 0000 0f01 0200 0600 0000 b200 0000 1001... 0000030: 0200 1900 0000 b800 0000 1201 0300 0100... 0000040: 0000 0600 0000 1a01 0500 0100 0000 d800... 0000050: 0000 1b01 0500 0100 0000 e000 0000 2801...(. 0000060: 0300 0100 0000 0200 0000 3201 0200 1400...2... 0000070: 0000 e800 0000 1302 0300 0100 0000 0200... 0000080: 0000 6987 0400 0100 0000 fc00 0000 2588..i...%. 0000090: 0400 0100 0000 2413 0000 f213 0000 2020...$... 00000a0: 2020 2020 2020 2020 2020 2020 2020 2020 00000b0: 2020 2020 2020 2020 2020 2020 2000 4361.Ca 00000c0: 6e6f 6e00 4361 6e6f 6e20 506f 7765 7253 non.canon PowerS 00000d0: 686f 7420 5358 3233 3020 4853 0000 0000 hot SX230 HS... 00000e0: 0000 0000 b400 0000 0100 0000 b400 0000... 00000f0: 0100 0000 3230 3131 3a30 373a 3134 2031...2011:07:14 1 0000100: 353a 3039 3a32 3700 2100 9a82 0500 0100 5:09:27.!... 0000110: 0000 8e02 0000 9d82 0500 0100 0000 9602... 0000120: 0000 2788 0300 0100 0000 6400 0000 3088..'...d...0. Position in file Actual binary data (written in hexadecimal) The same data, showing character representation

Remember... Don't get lost in the details and manipulations: Any base is a representation of an abstract number We are interested in working with the number, and computations are not "in a base" - the base is only useful for having it make sense to us or the computer Practice! You should be able to convert from one base to another. Lots of ways to practice: By hand: Pick a random number convert to binary and convert back - did you get the same value? This isn't foolproof: You could have made two mistakes! With a calculator: Many calculators (physical and software) do base conversion - check your randomly selected conversions. With a web site: Several web sites provide says to practice For example, see http://cs.iupui.edu/~aharris/230/binpractice.html Next: Other Representations Now we know all about representing numbers But computers also deal with text, web pages, pictures, sound/music, video,... How does that work?