Last Class We Covered ASCII values Short circuit evaluation Project 3

Slides:



Advertisements
Similar presentations
Virginia Standards of Learning 5.1 a. The student will read, write, & identify the place values of decimals through thousandths.
Advertisements

Place Value System For Whole Numbers. This is how the place value structure for whole numbers works: Millions HTOHTOHTO ThousandsOnes Note that.
MATH DRILLS. 376 three hundred seventy-six 508 five hundred eight.
REPRESENTING INFORMATION: BINARY, HEX, ASCII C ORRESPONDING R EADING : UDC C HAPTER 2 CMSC 150: Lecture 2.
© Maths Support Service 2007 Binary and Hexadecimal Numbers Next Slide AE98FD AE98FD.
IT-101 Section 001 Lecture #3 Introduction to Information Technology.
Web Colors. Web Colors: Up until now, we have been using only pre- defined color names, such as "orange" and "lightblue". As web designers, we need the.
Numbers ZERO 0 ONE 1 TWO 2 THREE 3 FOUR 4 FIVE 5.
Powerpoint Jeopardy Whole NumbersForms Whole Numbers Ordering Whole Numbers DecimalsOrdering Decimals Numbers
Computer Science and Software Engineering© 2014 Project Lead The Way, Inc. Bits and Bytes.
UNDERSTANDING NUMERALS TO HUNDRED MILLION. The third period in our number system is MILLIONS ONES __ __ __, THOUSANDS ___ ___ ___, MILLIONS ___ ___ __,,
Numbers can be written in 2 ways – FIGURES or WORDS Example: or one hundred twenty three thousand seven hundred sixty three.
Digital logic COMP214  Lecture 2 Dr. Sarah M.Eljack Chapter 1 1.
Number Systems.
Whole Numbers.
Place Value I ,
Expanded Form.
Cell phone use is prohibited.
Digital Logic and Computer Organization
Place Value.
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Reading Decimals.
Place Value II By Monica Yuskaitis.
1 - one 2 - two 3 - three 4 - four 5 - five 6 - six 7 - seven
STANDARD 5 TH A SUBJECT -- MATHEMATICS
Numbers Let's recap !.
Place Value II.
Numbers.
Digital Devices Integrated Circuits that operate on Digital Data are in 95% of every electrical powered device in the U.S. The theory of operation of these.
Last Class We Covered File I/O How to open a file
Place Value – Name the three periods
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
Place Value Basics: Whole Numbers
Place Value ,.
9 X Table Go for it!.
Coding Schemes and Number Systems
English Communication
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
Play.
Place Value Name: ______________________________
one thousand eight hundred twelve
Place Value.
Place Value.
Counting Chart: Numbers 1 to 100
1 ONE 2 TWO.
UNIT 1- NATURAL NUMBERS N 0, 1, 2, 3,
Last Class We Covered ASCII values Short circuit evaluation Project 3
COMS 161 Introduction to Computing
Place Value.
Last Class We Covered Asymptotic Analysis Run “time” Big O
Big numbers Play.
NUMBERS.
Chapter 3 DataStorage Foundations of Computer Science ã Cengage Learning.
Big numbers Play.
Thirty-six eighty thirty fifteen ten seventeen Forty-seven Forty-one
Last Class We Covered File I/O How to open a file
Primary 5 Mathematics Whole Numbers
Web Colors.
+/- Numbers Year 6 – Place value, rounding and mental methods
+/- Numbers Year 2 – Addition and subtraction of units within 100
3,050,020 = 3,000, Write the number in words. 6,140,050 = 6,000, ,
Last Class We Covered Sorting algorithms Searching algorithms
15-April 2019 LO: I can read, write, compare and order numbers with up to seven digits.
Our Number System.
Odd and Even Numbers.
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
Week 1 - Friday COMP 1600.
Presentation transcript:

CMSC201 Computer Science I for Majors Lecture 22 – Hexadecimal and Color Printing

Last Class We Covered ASCII values Short circuit evaluation Project 3 Deep copying the 2D list for the path Debug statements

Any Questions from Last Time?

Today’s Objectives To understand more about how data is represented inside the computer Hexadecimal numbers To show how to print in color To discuss details of Project 3 Conceptualizing the 3D maze list Not printing out dead ends

Hexadecimal Numbers

Decimal Representation Decimal uses 10 digits Decimal, deci = 10 The digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 hundred thousands ten thousands ten millions thousands millions hundreds tens ones 9 8 7 5 4 2 1 107 106 105 104 103 102 101 100

Binary Representation Binary uses 2 digits Binary, bi = 2 The digits used are 0 and 1 one hundred and twenty-eights sixty-fours thirty-twos sixteens eights fours twos ones 1 1 1 1 1 27 26 25 24 23 22 21 20

Hexadecimal Representation Hexadecimal (or just “hex”) uses 16 digits Hexadecimal, hex = 6 plus deci = 10  16 The digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 And letters A (10), B (11), C (12), D (13), E (14), and F (15) two hundred sixty-eight million four hundred thirty-five thousand four hundred and fifty-sixes sixty-five thousand five hundred and thirty-sixes sixteen million seven hundred seventy-seven thousand two hundred and sixteens one million forty-eight thousand five hundred and seventy-sixes four thousand and ninety-sixes two hundred and fifty-sixes sixteens ones F D A 8 6 3 1 167 166 165 164 163 162 161 160

Hexadecimal Representation Hexadecimal (or just “hex”) uses 16 digits Hexadecimal, hex = 6 plus deci = 10  16 The digits used are 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 And letters A (10), B (11), C (12), D (13), E (14), and F (15) 268435456s 16777216s 1048576s 65536s sixteens 4096s 256s ones F D A 8 6 3 1 167 166 165 164 163 162 161 160

Hex to Binary Conversion A hexadecimal digit can be easily represented as four digits of binary (with leading zeros) This makes conversion very simple 7A0F becomes 0111 1010 0000 1111 1100 0010 0110 1001 becomes C269 Hex Binary 0000 4 0100 8 1000 C 1100 1 0001 5 0101 9 1001 D 1101 2 0010 6 0110 A 1010 E 1110 3 0011 7 0111 B 1011 F 1111

Hex to Decimal Conversion Possible to convert between decimal and hex But it requires calculating out multiples of 16 Simpler to make a “side trip” binary as an in-between step when converting 240 becomes 1111 0000 becomes F0 F0 is equal to (15 * 161) + (0 * 160) = 240 + 0 = 240 7D becomes 0111 1101 becomes 125 7D is equal to (7 * 161) + (13 * 160) = 112 + 13 = 125

Number System Notation Because number systems share a subset of the same digits, it may be confusing which is which For example, what is the value of 10? In decimal it’s 10, in binary it’s 2, and in hex it’s 16 To prevent this, numbers may often be prefixed with 0b, 0d, or 0x (binary, decimal, hex): 0b1100 is binary, and has a value of 12 0x15 is hexadecimal, and has a value of 21

Printing in Color

ANSI Escape Codes To change the color of the background and text, we can use ANSI escape codes Works in many languages, not just Python To use the codes, simply use print() Just like “\t” turns into a tab, these won’t be “printed,” but will change how the text looks For example, print("\033[1;34;33m") changes text to blue, and background to yellow

Syntax of ANSI Escape Color Codes "\033[1 ; 34 ; 33m" \033[ Start of escape code m End of escape code NOTE: The starting [ is never closed! 1 Style to use (1 = bold) 30-37 Color to use for text 40-47 Color to use for background

Color Values and Reset The colors available are black, red, green, yellow, blue, magenta, cyan, and white For text color, they are 30 – 37, in order For background, they are 40 – 47, in order This is a perfect use for a dictionary! Store the color name as the key, and the number as the value; no need to memorize the numbers To reset to default colors, use "\033[0m"

Example Usages CODE = "\033[" RESET = CODE + "0m" START = CODE + "1;" BLACKG = ";40m" COLORS = {'black': '30', 'red': '31', 'green': '32', 'yellow': '33', 'blue': '34', 'magenta': '35', 'cyan': '36', 'white': '37'} >>> print(START + COLORS["cyan"] + BLACKG + \ "Dogs are great, even in cyan" + RESET) >>> print(START + COLORS["red"] + ";44m" + "Red on blue!" + RESET) >>> print("\033[1;30;42m") Dogs are great, even in cyan Red on blue! >>> print("Until it's reset, it prints black on green from now on!") Until it's reset, it prints black on green from now on!

Function to Print In Color Printing in color can be very useful when trying to distinguish different types of output Like debugging vs normal program output We’ve provided a function for you in the “Livecoding” section of the Documents page on the course website Feel free to use it in your Project 3 for debugging (Do not make your output hard to read, though!)

Project 3

Conceptualizing the 3D List If you follow the suggestion in the project, the maze will be represented as a 3D list Try not to think of this as a “real” 3D list – with a height, width, and depth The maze itself is not 3-dimensional, after all Instead, think of it as height, width, and INFO That third dimension is just information

Do Not Cheat on Project 3 Yes, this project has been given before Yes, in this class Yes, we have all of the old projects to compare it to Yes, this project has solutions on the internet Yes, we have copies of all of them Yes, we will go looking for new ones after it’s due Yes, you could pay someone else to do it Yes, we know of the sites where you can get this done Yes, we will spot “elegant” code that you didn’t write

Daily CS History Hemachandra Was a Jain scholar, poet, and polymath Lived from 1088 to 1173 in India Came up with the Fibonacci sequence 50 years before Fibonacci While coming up with different long and short syllable combinations for traditional poetry https://youtu.be/_32rgS8ClKw?t=1m54s

Announcements Project 3 is due on Friday, December 8th Design due on Friday, December 1st Survey #3 out on Friday, December 1st Final exam metacognition quiz out on BB same day Final exam is when? Friday, December 15th from 6 to 8 PM

Final Exam Locations Find your room ahead of time! ITE Building 102 - Sections 22, 28, 32 ITE Building 104 - Sections 2, 3, 4, 5, 6 Meyerhoff 030 - Sections 8, 9, 10, 11, 12, 14, 17, 18, 20 Performing Arts 132 - Sections 15, 16, 31 Sherman 003 - Sections 23, 26, 29, 30 Public Policy 105 - Sections 21, 24, 27

Image Sources Hemachandra: https://commons.wikimedia.org/wiki/File:Hemachandra.gif