Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage



Similar documents
CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

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

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Computer Science 217

CSI 333 Lecture 1 Number Systems

Python Programming: An Introduction to Computer Science

Example of Standard API

CS101 Lecture 24: Thinking in Python: Input and Output Variables and Arithmetic. Aaron Stevens 28 March Overview/Questions

Introduction to Python

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

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

The programming language C. sws1 1

Computer Layers. Hardware BOOT. Operating System. Applications

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Useful Number Systems

Copyright 2012 Pearson Education, Inc. Chapter 1 INTRODUCTION TO COMPUTING AND ENGINEERING PROBLEM SOLVING

VCL Access. VCL provides access to Linux and Windows 7 Virtual Machines. Users will only see those images that they are authorized to access.

1001ICT Introduction To Programming Lecture Notes

Introduction to UNIX and SFTP

Practical Programming, 2nd Edition

Objectives. Python Programming: An Introduction to Computer Science. Lab 01. What we ll learn in this class

OKLAHOMA SUBJECT AREA TESTS (OSAT )

University of Hull Department of Computer Science. Wrestling with Python Week 01 Playing with Python

AQA GCSE in Computer Science Computer Science Microsoft IT Academy Mapping

Remote Access to Unix Machines

Computer Organization

Ch. 10 Software Development. (Computer Programming)

Yale Software Library

10 STEPS TO YOUR FIRST QNX PROGRAM. QUICKSTART GUIDE Second Edition

Python Programming: An Introduction to Computer Science

Chapter 12 Programming Concepts and Languages

NYU-Poly VLAB Introduction LAB 0

Management Challenge. Managing Hardware Assets. Central Processing Unit. What is a Computer System?

CS3600 SYSTEMS AND NETWORKS

CHAPTER 1 ENGINEERING PROBLEM SOLVING. Copyright 2013 Pearson Education, Inc.

lesson 1 An Overview of the Computer System

Introduction to Computers and Programming

Fall Lecture 1. Operating Systems: Configuration & Use CIS345. Introduction to Operating Systems. Mostafa Z. Ali. mzali@just.edu.

Obj: Sec 1.0, to describe the relationship between hardware and software HW: Read p.2 9. Do Now: Name 3 parts of the computer.

CONNECTING TO DEPARTMENT OF COMPUTER SCIENCE SERVERS BOTH FROM ON AND OFF CAMPUS USING TUNNELING, PuTTY, AND VNC Client Utilities

CS 40 Computing for the Web

Sources: On the Web: Slides will be available on:

Informatica e Sistemi in Tempo Reale

New Mexico Broadband Program. Basic Computer Skills. Module 1 Types of Personal Computers Computer Hardware and Software

Stage 5 Information and Software Technology

Operating Systems. and Windows

System Structures. Services Interface Structure

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer

How to use SURA in three simple steps:

Software. Programming Language. Software. Instructor Özgür ZEYDAN. Bülent Ecevit University Department of Environmental Engineering

We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.

Memory is implemented as an array of electronic switches

CS 51 Intro to CS. Art Lee. September 2, 2014

Computer Literacy. Hardware & Software Classification

Kernel. What is an Operating System? Systems Software and Application Software. The core of an OS is called kernel, which. Module 9: Operating Systems

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Scalability and Classifications

Figure 1: Graphical example of a mergesort 1.

Introduction to Mirametrix EyeTracker

Memory Management Simulation Interactive Lab

Installing the Citrix Receiver Client

CE 504 Computational Hydrology Computational Environments and Tools Fritz R. Fiedler

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

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

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Computer Science 281 Binary and Hexadecimal Review

Functions of NOS Overview of NOS Characteristics Differences Between PC and a NOS Multiuser, Multitasking, and Multiprocessor Systems NOS Server

Waspmote IDE. User Guide

REMOTELY ACCESS YOUR FILES WITH THE FLAGLER FILECONNECT SYSTEM

Visualization Cluster Getting Started

Q N X S O F T W A R E D E V E L O P M E N T P L A T F O R M v Steps to Developing a QNX Program Quickstart Guide

EUROPEAN UNIVERSITY OF LEFKE MANAGEMENT INFORMATION SYSTEMS DEPARTMENT COURSE DESCRIPTION

Code::Blocks Student Manual

Frequently Asked Questions

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Using Virtual Machines

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Network operating systems typically are used to run computers that act as servers. They provide the capabilities required for network operation.

OPERATING SYSTEM SERVICES

Outline: Operating Systems

International Engineering Journal For Research & Development

CSC230 Getting Starting in C. Tyler Bletsch

The IDL Virtual Machine

Chapter 13: Program Development and Programming Languages

Raspberry Pi Setup Tutorial

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

Outline. multiple choice quiz bottom-up design. the modules main program: quiz.py namespaces in Python

Code Estimation Tools Directions for a Services Engagement

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Software: Systems and Application Software

NUMBER SYSTEMS. William Stallings

Introduction to programming

(Refer Slide Time: 02:39)

Computer Programming I & II*

CPSC 226 Lab Nine Fall 2015

4.1 Introduction 4.2 Explain the purpose of an operating system Describe characteristics of modern operating systems Control Hardware Access

1 PERSONAL COMPUTERS

Chapter 3. Operating Systems

Transcription:

Outline 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments MCS 260 Lecture 2 Introduction to Computer Science Jan Verschelde, 14 January 2015 Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 1 / 23

Computer Architecture Hardware & Software A computer system consists of 1 Hardware: physical components of computer computer: processor, memory, bus,... peripherals: printer, screen, keyboard, mouse,... 2 Software: programs executed by computer basic software like the Operating System (OS) either Unix (e.g.: Solaris, GNU-Linux, Mac OS X) or Windows (the OS of Microsoft) application software such as IDLE, Sage,... application software needs operating system to run Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 2 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 3 / 23

Hardware Components processor (or CPU: Central Processing Unit) does the computing and coordinates data transfer memory (or RAM: Random Access Memory) is used to store data and programs, of limited capacity, and volatile (lost if power off). storage persistently stores large quantities of data and programs, slower access to storage than to memory, but larger than RAM peripherals are used to communicate with computer system bus connects CPU, RAM, storage, and peripherals Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 4 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 5 / 23

Programming Environments what it takes to run programs editor : is used to write source code compiler : translates source code into an object, an executable program if code is bug free interpreter : executes high level code directly linker : combines several objects into one single executable program debugger : helps user to locate bugs, allowing a stepwise execution of the program use an IDE: Integrated Development Environment Pythons IDE is called IDLE Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 6 / 23

Executing Programs how programs are executed high level programming languages are oriented towards the convenience of the programmer an assembler language offers symbols to the basic instructions for writing machine code The Python Virtual Machine: *.py source *.pyc bytecode PVM runtime The Python interpreter creates bytecode that is then executed by the Python Virtual Machine at runtime. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 7 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 8 / 23

Installing Python on your desktop or laptop Free to download from www.python.org. Unix most Linux distributions have Python installed, or else contact your system administrator. Mac OS X like with unix you can download the source or run Python 2.7.5 for Macintosh OS X (universal installer both for PPC and IntelMacs). Computers in ACCC labs (should) have Python installed. Windows run the Python 2.7.5 windows installer. Labs in 1200 SEO and 2263 SEO have Python installed. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 9 / 23

running Python on people.uic.edu The computer people.uic.edu is for serving your web publishing needs for all UIC students, faculty, and staff. It runs Python 2.7.5. From a terminal window on Mac OS X in lab SEL 2263, type ssh -X people.uic.edu and then you can type idle or python. In a Windows lab on campus: 1 Launch PuTTy from Internet Browsers & Tools. 2 Log in to people.uic.edu (host name) with your netid. 3 To download a script from the course web site: wget http://www.math.uic.edu/~jan/mcs260/hello.py 4 Type python hello.py to run the script. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 10 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 11 / 23

Executing Python code program prints "hello world!" Ways to run python programs: 1 In a Python session, type commands at the prompt: >>> print hello world! 2 Running programs at the command prompt: 1 Save Python commands in a file, e.g.: hello.py. 2 Type python hello.py at the command prompt. 3 On windows, double click a file with.py extension. 4 In IDLE, go to the run menu in the editor. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 12 / 23

Interactive Python code Let us write a program that asks for our name, as input. And then, as output, writes hello followed by our name. input The raw_input() function accepts only text input: >>> NAME = raw_input( Who\ s there? ) Displays Who s there? on screen and assigns what the user types in to the variable NAME. output With NAME in its argument, the print command displays the value of NAME: >>> print hello, NAME,! develop Python code interactively at the prompt Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 13 / 23

our first interactive program running at the command prompt The file hello_there.py contains # L-2 MCS 260 an interactive program NAME = raw_input( Who\ s there? ) print hello, NAME,! The # signs the start of a comment, the line following # is ignored by the interpreter. At the command prompt, we type python hello_there.py On Windows, double clicking on the file with.py extension will execute the program. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 14 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 15 / 23

Decimal Notation of Numbers The value of 284 = 2 10 2 + 8 10 1 + 4 10 0. 2,8,4 are the digits of the number, 10 is the base. The position of each digit determines its contribution to the value of the number. For any base B, a number n is denoted by m coefficients c i, i = m, m 1,..., 1, 0, 0 c i < B: n = c m B m + c m 1 B m 1 + + c 1 B 1 + c 0 B 0. From base five to decimal notation: 2104 5 = 2 5 3 + 1 5 2 + 0 5 1 + 4 5 0 = 250 + 25 + 0 + 4 = 279 10 Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 16 / 23

Binary Numbers The base is two, the coefficients are bits {0, 1}. The first 16 natural numbers need 4 bits: 0000 = 0 0001 = 1 0010 = 2 0011 = 3 0100 = 4 0101 = 5 0110 = 6 0111 = 7 1000 = 8 1001 = 9 1010 = A 1011 = B 1100 = C 1101 = D 1110 = E 1111 = F The hexadecimal digits are 0,1,2,...,9,A,B,C,D,E,F. It is straightforward to convert binary into hexadecimal and hexadecimal into binary numbers. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 17 / 23

Converting Numbers from decimal to binary Convert 123 into binary format: n n/2 n mod 2 123 61 1 123 = 61 2 + 1 61 30 1 61 = 30 2 + 1 30 15 0 30 = 15 2 + 0 15 7 1 15 = 7 2 + 1 7 3 1 7 = 3 2 + 1 3 1 1 3 = 1 2 + 1 1 0 1 1 = 0 2 + 1 123 = 1 + 2 61 = 1 + 2 (1 + 2 30) = 1 + 2 (1 + 2 (0 + 2 15)) = 1 + 2 (1 + 2 (0 + 2 (1 + 2 7))) =... So 123 = 1111011 = 7B. Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 18 / 23

Flowchart conversion algorithm n = input() r is remainder of n/2 print r; n := n/2 n == 0? Yes stop No Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 19 / 23

Computer Architecture first steps with Python 1 Computer Architecture hardware components programming environments 2 Getting Started with Python installing Python executing Python code 3 Number Systems decimal and binary notations running Sage 4 Summary + Assignments Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 20 / 23

Running Sage Ways to compute with Sage: a notebook blends commands with commentary graphical user interface runs in a browser command line use if no graphical output is needed and more dedicated to computationally intensive jobs language is Python, with some variation Python (version < 3.0): Sage: >>> 68/25 2 sage: 68/25 68/25 Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 21 / 23

Number Systems with Python and Sage Hexadecimal conversions in Python with the % operator: >>> "%X" % 123 7B >>> %x % 123 7b The same calculations are possible in Sage. Sage has much more refined number systems: 1 integers and modular arithmetic 2 exact calculations with rational numbers 3 arbitrary precision float and complex 4 algebraic numbers Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 22 / 23

Summary + Assignments Recommended reading: Python tutorial on http://docs.python.org/2/tutorial sections 1.4 & 1.5 of Computer Science. An Overview chapter 1 of Python Programming in Context Assignments: 1 Given the base and a sequence of coefficients of a number, draw the flowchart of the algorithm to evaluate the number. 2 Write down pseudocode for the algorithm to compute the binary representation of a number. 3 Compute examples of general number conversions from any base to any other base. 4 What is the algorithm for such general conversions? Intro to Computer Science (MCS 260) Computer Architecture L-2 14 January 2015 23 / 23