Binary Numbers CSE 120 Spring 2017

Slides:



Advertisements
Similar presentations
© 2004, Robert K. Moniot Binary and Hex How to count like a computer.
Advertisements

A-Level Computing#BristolMet Session Objectives#8 express numbers in binary, octal and hexadecimal explain the use of code to represent a character set.
Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems.
How Computers Think: Binary, Decimal and Hexadecimal For NYSCPT Summer Institute, NYU Andrew O’Neill Columbia University.
Computer Arithmetic: Binary, Octal and Hexadecimal Presented by Frank H. Osborne, Ph. D. © 2005 ID 2950 Technology and the Young Child.
Binary and Decimal Numbers
Hexadecimal and ASCII Lesson Objective: Understand the purpose of ASCII and how to use it. Lesson Outcome: Convert between Hexadecimal and ASCII Convert.
©Brooks/Cole, 2003 Chapter 2 Data Representation.
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
Chapter 2 Computer Hardware
EX_01.1/46 Numeric Systems. EX_01.2/46 Overview Numeric systems – general, Binary numbers, Octal numbers, Hexadecimal system, Data units, ASCII code,
The Hexadecimal Number System and Memory Addressing ISAT 121.
CS161 Computer Programming Instructor: Maria Sabir Fall 2009 Lecture #1.
CMSC 104, Lecture 051 Binary / Hex Binary and Hex The number systems of Computer Science.
1 Data Representation Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System Powered by DeSiaMore.
1 COMS 161 Introduction to Computing Title: The Digital Domain Date: September 6, 2004 Lecture Number: 6.
How a Computer Processes Information. Java – Numbering Systems OBJECTIVE - Introduction to Numbering Systems and their relation to Computer Problems Review.
Number Representation (Part 1) Computer Architecture (Fall 2006)
Some Computer Science Conceptual Background Material Doug Hogan This version for UIC Spring 2016 CS 107.
1 Digital Logic Design Engr. Kashif Shahzad. 2 What’s Course About?  Digital logic, focusing on the design of computers  Stay above transistor level.
Binary a. express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal;
Base 16 (hexadecimal) Uses the decimal digits and the first letters of the alphabet to encode 4 binary bits (16=2 4 ) abcdef or ABCDEF.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
DECIMAL, BINARY, AND HEXADECIMAL. Decimal Numbering System Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Represent larger numbers as a sequence of digits.
DATA REPRESENTATION - TEXT
Some basic concepts underlying computer archi­tecture
Binary Representation in Text
Binary Representation in Text
Computer Architecture and Number Systems
Topic: Binary Encoding – Part 1
Number Systems.
Binary Numbers CSE 351 Spring 2017
Binary Notation and Intro to Computer Graphics
Unit 18: Computational Thinking
Processing Introduction CSE 120 Spring 2017
ECE Application Programming
Dr. Clincy Professor of CS
Digital Electronics Jess 2008.
Information Support and Services
The Hardware/Software Interface CSE 351 Autumn 2017
Functions in Processing CSE 120 Spring 2017
EPSII 59:006 Spring 2004.
Lightbot and Functions CSE 120 Winter 2017
Chapter 3 Data Representation
RFID - EN Encoding information Encoding information J.-D. Chatelain.
Number System conversions
Coding Schemes and Number Systems
BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.
LING 388: Computers and Language
Dr. Clincy Professor of CS
Variables & Datatypes CSE 120 Spring 2017
Integers II CSE 410 Winter 2017 Instructor: Teaching Assistants:
Data Representation Conversion 05/12/2018.
Introduction to Binary
Machine Architecture and Number Systems
Fundamentals of Data Representation
Digital Electronics and Microprocessors
COMS 161 Introduction to Computing
INFO/CSE 100, Spring 2005 Fluency in Information Technology
Number Systems Lecture 2.
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
How Computers Store Data
Machine Architecture and Number Systems
Machine Architecture and Number Systems
Machine Architecture and Number Systems
Comp Org & Assembly Lang
Abstraction – Number Systems and Data Representation
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Presentation transcript:

Binary Numbers CSE 120 Spring 2017 Instructor: Teaching Assistants: Justin Hsia Anupam Gupta, Braydon Hall, Eugene Oh, Savanna Yee This is why you should never Instagram your boarding pass There’s a problem with the way airlines manage passenger information – and Instagram is making it worse. After decades of technological progress, airline’s proof that you are who you say you are still boils down to a single six-digit number, encoded in the barcode on your boarding pass. And because of Instagram (particularly #boardingpass), those bar codes are easy to find. http://www.theverge.com/2017/1/10/ 14226034/instagram-boarding-pass- security-problem-bad-idea

Administrivia Assignments: Any questions on Canvas submissions? Website Setup due today (3/31) Symbolic Lightbot due today (3/31) Personal Values due Sunday (4/2) Lightbot Functions due Monday (4/3) Any questions on Canvas submissions? Any questions about weekly reading and reading checks?

Discussion: Counting How high can you count using just your two hands? Discuss with your neighbor(s) Other ways to count or keep score? Example: Ultimate Frisbee scorekeeping

Lecture Outline Decimal, Binary, and Hexadecimal Base Conversion Binary Encoding

Decimal Numbering System Ten symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Represent larger numbers as a sequence of digits Each digit is one of the available symbols Example: 7061 in decimal (base 10) 706110 = (7 × 103) + (0 × 102) + (6 × 101) + (1 × 100) Ones digit, Tens digit, Hundreds digit, etc.

Octal Numbering System Eight symbols: 0, 1, 2, 3, 4, 5, 6, 7 Notice that we no longer use 8 or 9 Base comparison: Base 10: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12… Base 8: 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14… Example: What is 70618 in base 10? 70618 = (7 × 83) + (0 × 82) + (6 × 81) + (1 × 80) = 363310

Peer Instruction Question What is 348 in base 10? 3210 3410 710 2810 3510 Think on your own for a minute, then discuss with your neighbor(s) Vote at http://PollEv.com/justinh

Binary and Hexadecimal Binary is base 2 Symbols: 0, 1 Convention: 210 = 102 = 0b10 Example: What is 0b110 in base 10? 0b110 = 1102 = (1 × 22) + (1 × 21) + (0 × 20) = 610 Hexadecimal (hex, for short) is base 16 Symbols? 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, …? Convention: 1610 = 1016 = 0x10 Example: What is 0xA5 in base 10? 0xA5 = A516 = (10 × 161) + (5 × 160) = 16510 9, A, B, C, D, E, F

Peer Instruction Question Which of the following orderings is correct? 0xC < 0b1010 < 11 0xC < 11 < 0b1010 11 < 0b1010 < 0xC 0b1010 < 11 < 0xC 0b1010 < 0xC < 11 Think on your own for a minute, then discuss with your neighbor(s) Vote at http://PollEv.com/justinh

Lecture Outline Decimal, Binary, and Hexadecimal Base Conversion Binary Encoding

Converting to Base 10 Can convert from any base to base 10 0xA5 = A516 = (10 × 161) + (5 × 160) = 16510 We learned to think in base 10, so this is fairly natural for us Challenge: Convert into other bases (e.g. 2, 16)

Challenge Question Convert 1310 into binary Hints: 23 = 8 22 = 4 21 = 2 20 = 1 Think on your own for a minute, then discuss with your neighbor(s) No voting for this question

Converting from Decimal to Binary Given a decimal number N: List increasing powers of 2 from right to left until ≥ N Then from left to right, ask is that (power of 2) ≤ N? If YES, put a 1 below and subtract that power from N If NO, put a 0 below and keep going Example: 13 to binary 24=16 23=8 22=4 21=2 20=1

Converting from Decimal to Base B Given a decimal number N: List increasing powers of B from right to left until ≥ N Then from left to right, ask is that (power of B) ≤ N? If YES, put how many of that power go into N and subtract from N If NO, put a 0 below and keep going Example: 165 to hex 162=256 161=16 160=1

Converting Binary ↔ Hexadecimal Hex → Binary Substitute hex digits, then drop any leading zeros Example: 0x2D to binary 0x2 is 0b0010, 0xD is 0b1101 Drop two leading zeros, answer is 0b101101 Binary → Hex Pad with leading zeros until multiple of 4, then substitute each group of 4 Example: 0b101101 Pad to 0b 0010 1101 Substitute to get 0x2D Base 10 Base 2 Base 16 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F

Binary → Hex Practice Convert 0b100110110101101 How many digits? Pad: Substitute: Base 10 Base 2 Base 16 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F

Base Comparison Why does all of this matter? Humans think about numbers in base 10, but computers “think” about numbers in base 2 Binary encoding is what allows computers to do all of the amazing things that they do! Base 10 Base 2 Base 16 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 A 11 1011 B 12 1100 C 13 1101 D 14 1110 E 15 1111 F

Aside: Why Base 2? Electronic implementation Easy to store with bi-stable elements Reliably transmitted on noisy and inaccurate wires Other bases possible, but not yet viable: DNA data storage (base 4: A, C, G, T) is a hot topic Quantum computing 0.0V 0.5V 2.8V 3.3V 1 adenine (A), cytosine (C), guanine (G), or thymine (T)

Lecture Outline Decimal, Binary, and Hexadecimal Base Conversion Binary Encoding

Numerical Encoding AMAZING FACT: You can represent anything countable using numbers! Need to agree on an encoding Kind of like learning a new language Examples: Decimal Integers: 0→0b0, 1→0b1, 2→0b10, etc. English Letters: CSE→0x435345, yay→0x796179 Emoticons: 😃 0x0, 😞 0x1, 😎 0x2, 😇 0x3, 😈 0x4, 🙋 0x5 Base 2 is too hard for humans to read, so we use base 16 as a convenient way to hold what is effectively binary data in our brains.

Binary Encoding With N binary digits, how many “things” can you represent? Need N binary digits to represent 𝑛 things, where 2N ≥𝑛 Example: 5 binary digits for alphabet because 25 = 32 > 26 A binary digit is known as a bit A group of 4 bits (1 hex digit) is called a nibble A group of 8 bits (2 hex digits) is called a byte 1 bit → 2 things, 1 nibble → 16 things, 1 byte → 256 things

So What’s It Mean? A sequence of bits can have many meanings! Consider the hex sequence 0x4E6F21 Common interpretations include: The decimal number 5140257 The characters “No!” The background color of this slide The real number 7.203034 × 10-39 It is up to the program/programmer to decide how to interpret the sequence of bits

Binary Encoding – Colors RGB – Red, Green, Blue Additive color model (light): byte (8 bits) for each color Commonly seen in hex (in HTML, photo editing, etc.) Examples: Blue→0x0000FF, Gold→0xFFD700, White→0xFFFFFF, Deep Pink→0xFF1493

Binary Encoding – Characters/Text ASCII Encoding (www.asciitable.com) American Standard Code for Information Interchange

Binary Encoding – Video Games As programs run, in-game data is stored somewhere In many old games, stats would go to a maximum of 255 Pacman “kill screen” http://www.numberphile.com/videos/255.html

Binary Encoding – Files and Programs At the lowest level, all digital data is stored as bits! Layers of abstraction keep everything comprehensible Data/files are groups of bits interpreted by program Program is actually groups of bits being interpreted by your CPU Computer Memory Demo Can try to open files using a text editor From vim: %!xxd

Summary Humans think about numbers in decimal; computers think about numbers in binary Base conversion to go between them Hexadecimal is more human-readable than binary All information on a computer is binary Binary encoding can represent anything! Computer/program needs to know how to interpret the bits

Summary