1 CS 177 Week 2 Recitation Slides Introduction. 2 Announcements.

Slides:



Advertisements
Similar presentations
DATA REPRESENTATION CONVERSION.
Advertisements

The Binary Numbering Systems
Python November 14, Unit 7. Python Hello world, in class.
Data Representation in Computers
CS 177 Programming with Multimedia Objects Recitation.
Binary Numbers.
Announcements Class / Recitation slides available on the syllabus page Check morning of for latest version We will start grading clickers next lecture.
(2.1) Fundamentals  Terms for magnitudes – logarithms and logarithmic graphs  Digital representations – Binary numbers – Text – Analog information 
Vahé Karamian Python Programming CS-110 CHAPTER 3 Computing with Numbers.
C Programming Lecture 3. The Three Stages of Compiling a Program b The preprocessor is invoked The source code is modified b The compiler itself is invoked.
Numbering Systems CS208.
Computing with Numbers CSC 161: The Art of Programming Prof. Henry Kautz 9/14/2009.
General Computer Science for Engineers CISC 106 Lecture 02 Dr. John Cavazos Computer and Information Sciences 09/03/2010.
Chapter 3 Section 1 Number Representation Modern cryptographic methods, unlike the classical methods we just learned, are computer based. Representation.
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
Number systems, Operations, and Codes
Chapter1: Number Systems
CPS120: Introduction to Computer Science Computer Math: Converting to Decimal.
Positional Notation 642 in base 10 positional notation is:
Order of Operations.
CS 177 Week 4 Recitation Slides Variables, Files and Functions.
CS 102 Computers In Context (Multimedia)‏ 01 / 26 / 2009 Instructor: Michael Eckmann.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Copyright © 2012, 2009, 2005, 2002 Pearson Education, Inc. Chapter 3 Decimals.
THE BINARY SYSTEM.
Data Representation, Number Systems and Base Conversions
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Number Systems Denary Base 10 Binary Base 2 Hexadecimal Base 16
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Introduction To Number Systems Binary System M. AL-Towaileb1.
Arithmetic Operators. Operators In Programming Most computer programming languages use the following symbols for their operators: +  add -  subtract.
ORDER OF OPERATIONS. What is the correct method for solving numerical problems?
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
The Hexadecimal System is base 16. It is a shorthand method for representing the 8-bit bytes that are stored in the computer system. This system was chosen.
Number Systems. ASCII – American Standard Code for Information Interchange – Standard encoding scheme used to represent characters in binary format on.
Lesson 6 Binary Understand what Binary Code means and apply this knowledge Understand how data is represented using bit systems and be able to change decimal.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
Understanding Computers
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Some basic concepts underlying computer archi­tecture
Introduction To Number Systems
Understanding binary Understanding Computers.
3 – Boolean Logic and Logic Gates 4 – Binary Numbers
BINARY CODE.
CHAPTER 1 : INTRODUCTION
Introduction to Chapter 2
Assignment statement:
Variables, Expressions, and IO
Number System conversions
Fundamentals & Ethics of Information Systems IS 201
IT 0213: INTRODUCTION TO COMPUTER ARCHITECTURE
University of Gujrat Department of Computer Science
2 Number Systems and Codes Edited by Jerry Bernardini.
Dr. Clincy Professor of CS
Learning Outcomes –Lesson 4
Chapter 2: Number Systems
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
How Computers Store Data
Chapter Four Data Representation in Computers By Bezawit E.
Decimal / Binary Conversions
Beyond Base 10: Non-decimal Based Number Systems
Solve in Groups (Standard Write and Interpret numerical expressions )
Chapter 3 - Binary Numbering System
Introduction to Python
Presentation transcript:

1 CS 177 Week 2 Recitation Slides Introduction

2 Announcements

What Computers Understand? Computers can only understand Encoding of numbers. So what is the meaning of Encoding ?

Computers are electronic devices that react to wires. Computer hardware produces (patterns of) voltages (variations of electric current). If a wire has a voltage on it, we say that it encodes 1. If it has no voltage, we say 0. How can we represent voltages?

Encoding is the activity of converting data or information into some symbol. Computer understand just two symbols, 0 and 1. 0 and 1 are also numbers (in the binary number system). A binary number system gets its name from having just two digits, O and 1. Encoding

Binary Number System Represents numeric values using two symbols, 0 and 1 Also called Base-2 number system To convert decimal numbers into binary, divide the decimal number repeatedly by 2  Remainder at each step becomes a digit of the binary number  Repeat until result of further division becomes zero 6

Decimal to Binary Conversion To convert the decimal number 26 into binary, In a computer, 26 is represented as

Binary to Decimal Conversion Multiply successive digits of the binary number with increasing powers of 2 Add the products to get the decimal number 8

2 3 = 8 * 1 = = 4 * 1 = = 2 * 0 = = 1 * 1 = 1 Interpreted as 13 Examples

Can you do this?

Example 1: Emoticons What if you want to tell a friend your emotion by texting them on your mobile phone (without texting a long message)? You can use emoticons… Emoticons are an encoding of emotions: :) I’m happy, I like it :( I’m unhappy, I dislike it :’( I’m crying and sad You are using a combination of symbols (parenthesis, punctuation symbols), that you normally you use in writing, to represent your emotions.

Example 2: Character Codes Now suppose that you want to encode the previous 3 symbols : ( ) using numbers… You may use the ASCII code …

ASCII Table

Definitions Bit: is the smallest unit of data in a computer that has a single binary value either 0 or 1. Byte: is a unit of data that is eight binary digits long. How many bits are there in 5 bytes?

Questions How many combinations can be represented in one bit? Two bits? What about three bits and four bits?

So, Decoding is the activity of converting code into plain text. Decoding

Statements On starting Python, there is a Python prompt indicating that Python is ready to accept a command. These commands are called statements. Different kinds of statements >>> print("Hello, world“) Hello, world >>> print(2+3) 5 >>> print("2+3=", 2+3) 2+3= 5 >>> 17

Simple Statements  Assigning values >>> a = 10 >>> b = 2 >>> c = 4  Arithmetic Operations >>> x = a + b >>> y = a – b >>> p = a/b >>> q = a/c 18

Operator Precedence Order of mathematical operations in an expression Python uses the same precedence as in Mathematics  Terms inside parentheses or brackets  Exponents and Roots  Multiplication and Division (Left to Right)  Addition and Subtraction (Left to Right) 19

Print Statements From previous example, >>> print(x) 12 >>> print("y =", y) y = 8 >>> print("Sum of a and b :", a + b) Sum of a and b : 12 Other examples, >>> print("Hello, World!") Hello, World! >>> print("Hello", ",", "World!") Hello, World! We will revisit the print() statement later 20

Programming Tip Use print() statements for debugging >>> a = * 6 >>> b = * 3 >>> print(a/b) 5.0 Did we get the expected result? 21

Print statements for debugging Print statements allow us to observe the operator precedence >>> a = * 6 >>> print("a = ", a) a = 20 >>> b = * 3 >>> print("b = ", b) b = 4 >>> print("Result = ", a/b) Result = 5.0 Print statements allow us to observe various variables and the values they have during the course of the program 22

Python Math Library Provides access to mathematical functions Documentation –  math.pow(x, y) - Return x raised to the power y.  math.sqrt(x) - Return the square root of x.  math.factorial(x) - Return x factorial.  math.ceil(x) - Return the ceiling of x.  math.floor(x) - Return the floor of x. 23

>>> import math >>> a = math.factorial(6) >>> print(a) 720 >>> b = math.sqrt(123) >>> print(b) >>> c = math.floor(5.9) >>> print(c) 5 24 Examples

>>> x = math.factorial(4) * math.pow(2,3) >>> print(x) >>> y = 5.5 >>> z = math.floor(y) * math.ceil(y) >>> print(z) Examples