Introduction to Programming

Similar documents
The programming language C. sws1 1

Pemrograman Dasar. Basic Elements Of Java

Computer Science 281 Binary and Hexadecimal Review

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

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

Number Representation

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

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

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window)

Variables, Constants, and Data Types

Binary Representation

Informatica e Sistemi in Tempo Reale

Base Conversion written by Cathy Saxton

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

Chapter 4: Computer Codes

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

DNA Data and Program Representation. Alexandre David

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

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

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

6.087 Lecture 2 January 12, 2010

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

Caml Virtual Machine File & data formats Document version: 1.4

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void

How To Write Portable Programs In C

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

Simple Image File Formats

Useful Number Systems

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

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

CSI 333 Lecture 1 Number Systems

MS ACCESS DATABASE DATA TYPES

Numbering Systems. InThisAppendix...

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Subject knowledge requirements for entry into computer science teacher training. Expert group s recommendations

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Green = 0,255,0 (Target Color for E.L. Gray Construction) CIELAB RGB Simulation Result for E.L. Gray Match (43,215,35) Equal Luminance Gray for Green

Chapter 1: Digital Systems and Binary Numbers

Data Storage. 1s and 0s

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Binary Numbers. Binary Octal Hexadecimal

Solution for Homework 2

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

C++ Language Tutorial

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

Data Storage 3.1. Foundations of Computer Science Cengage Learning

Chapter 7D The Java Virtual Machine

Objective-C Tutorial

CHAPTER 3 Boolean Algebra and Digital Logic

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

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

Data Storage. Chapter 3. Objectives. 3-1 Data Types. Data Inside the Computer. After studying this chapter, students should be able to:

1. True or False? A voltage level in the range 0 to 2 volts is interpreted as a binary 1.

First Bytes Programming Lab 2

Introduction to Programming

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

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

HOMEWORK # 2 SOLUTIO

VB.NET Programming Fundamentals

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Principles of Database Management Systems. Overview. Principles of Data Layout. Topic for today. "Executive Summary": here.

About The Tutorial. Audience. Prerequisites. Copyright & Disclaimer

Section 1.4 Place Value Systems of Numeration in Other Bases

Programming languages C

Lecture 2. Binary and Hexadecimal Numbers

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Outline Basic concepts of Python language

Simple C++ Programs. Engineering Problem Solving with C++, Etter/Ingber. Dev-C++ Dev-C++ Windows Friendly Exit. The C++ Programming Language

Part 1 Foundations of object orientation

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

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

CSCE 110 Programming I Basics of Python: Variables, Expressions, and Input/Output

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Systems I: Computer Organization and Architecture

Chapter 2 Elementary Programming

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

Chapter One Introduction to Programming

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Habanero Extreme Scale Software Research Project

The New IoT Standard: Any App for Any Device Using Any Data Format. Mike Weiner Product Manager, Omega DevCloud KORE Telematics

Introduction to Java

Unsigned Conversions from Decimal or to Decimal and other Number Systems

The University of Alabama in Huntsville Electrical and Computer Engineering CPE Test #4 November 20, True or False (2 points each)

A list of data types appears at the bottom of this document. String datetimestamp = new java.sql.timestamp(system.currenttimemillis()).

OKLAHOMA SUBJECT AREA TESTS (OSAT )

Organization of Records in Blocks

Logic in Computer Science: Logic Gates

Data Storage: Each time you create a variable in memory, a certain amount of memory is allocated for that variable based on its data type (or class).

Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

C++ INTERVIEW QUESTIONS

Compiling CAO: from Cryptographic Specifications to C Implementations

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

1. Boolean Data Type & Expressions Outline. Basic Data Types. Numeric int float Non-numeric char

Java Interview Questions and Answers

Memory Systems. Static Random Access Memory (SRAM) Cell

The C Programming Language course syllabus associate level

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects.

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

This 3-digit ASCII string could also be calculated as n = (Data[2]-0x30) +10*((Data[1]-0x30)+10*(Data[0]-0x30));

Transcription:

Introduction to Programming SS 2012 Adrian Kacso, Univ. Siegen adriana.dkacsoa@duni-siegena.de Tel.: 0271/740-3966, Office: H-B 8406 Stand: April 25, 2012 Betriebssysteme / verteilte Systeme Introduction to Programming (1) i Introduction to Programming SS 2012 2 Data: Variables, Types, Constants Betriebssysteme / verteilte Systeme Introduction to Programming (1) 36

2 Data: Variables, Types, Constants... Contents Variables Data types Constants Betriebssysteme / verteilte Systeme Introduction to Programming (1) 37 2.1 Variables Reminder: the computer from inside (VERY simplistic) registers registers memory bus CPU ALU disk Betriebssysteme / verteilte Systeme Introduction to Programming (1) 38

2.1 Variables... Variables A variable is (or can be viewed as) a named memory region that can be used to store data of a specific type int myvar Memory Address 100 101 102 103 Each memory cell has the size of one byte The size of the variable depends on its type Betriebssysteme / verteilte Systeme Introduction to Programming (1) 39 2.2 Types Simple data types and their sizes type size int 4 bytes integer number (size depends on the machine!) short int 2 bytes integer number long int 4 bytes integer number float 4 bytes floating point number double 8 bytes floating point number char 1 byte single ASCII character bool 1 byte Boolean value (truth value) Betriebssysteme / verteilte Systeme Introduction to Programming (1) 40

2.2 Types... signed and unsigned integers int is a signed integer:... 3, 2, 1, 0, 1, 2, 3,... unsigned short int is an unsigned integer: 0, 1, 2,..., 65534, 65535 Note: The most significant bit indicates the sign of the integer Two s complement (C2) representation for signed integers: Allows the use of binary arithmetic operations on signed integers, yielding the correct 2 s complement results. Calculation of C2: invert the binary equivalent, and then add one. Betriebssysteme / verteilte Systeme Introduction to Programming (1) 41 2.2 Types... Value ranges type size range unsigned short int 2 bytes 0 to 65,535 short int 2 bytes -32,768 to 32,767 unsigned long int 4 bytes 0 to 4,294,967,295 long int 4 bytes -2,147,483,648 to 2,147,483,647 float 4 bytes 1.2e-38 to 3.4e38 double 8 bytes 2.2e-308 to 1.8e308 char 1 byte 256 (ASCII) character values bool 1 byte true or false Betriebssysteme / verteilte Systeme Introduction to Programming (1) 42

2.2 Types... Caution: Integer arithmetic (e.g., with int or char values) does not check for overflow! Precision of floating point arithmetic is limited! with float or double values, the lack of precision can ruin the results of your program! Don t worry: All you need is keep this in mind and be careful! Betriebssysteme / verteilte Systeme Introduction to Programming (1) 43 2.3 Declarations Declaring (defining) a variable All variables must be declared before they can be used Declaration: Type, followed by the name, followed by ; Example: unsigned long int myage; The name can be any sequence of the following characters: a... z, A... Z, 0... 9, but names must not start with a digit! Remember: C++ is case-sensitive: myage is not the same name as myage Some special words (keywords) are not allowed as variable names, e.g.: int, if, while Betriebssysteme / verteilte Systeme Introduction to Programming (1) 44

2.3 Declarations... Declaring more than one variable at a time unsigned int myage, myweight; // two unsigned ints long area, width, length; // three longs Basic Rule for Variable Names: Use names that make sense! Use names that have sufficient intellectual distance!!! Bad example: unsigned int x1, x2, x3; Good example: unsigned int myage, myweight; Betriebssysteme / verteilte Systeme Introduction to Programming (1) 45 2.3 Declarations... Assignment and initialization Assignment: int Width;... Width = 5; Initialization (= creation with initial assignment): int Width = 5; Before the first assignment, the content of a variable is undefined! always make sure that variables are initialized before you use them! Betriebssysteme / verteilte Systeme Introduction to Programming (1) 46

2.4 Constants Literal constants 42 012 0xFF -23.5e16 true a "this is a string\n" type: int type: int (octal notation) type: int (hexadecimal notation) type: double type: bool type: char type: (we will see later; 6.1) Use literal (numerical) constants only very carefully! Documentation, code maintainance,... Betriebssysteme / verteilte Systeme Introduction to Programming (1) 47 2.4 Constants... Symbolic constants Literal: students = classes * 15; Symbolic: const unsigned short int studentsperclass = 15; students = classes * studentsperclass; the keyword const says that this variable cannot be modified Advantages: prepare for change compiler can type-check operations on constant Betriebssysteme / verteilte Systeme Introduction to Programming (1) 48

2.4 Constants... Enumerated constants (enumerated types) Definition of an enumerated data type: enum Color { RED, GREEN, BLUE, BLACK, WHITE, CYAN, MAGENTA }; Color c = GREEN; Note that Color now is a new type (The enumerated constants get assigned int values. However, this is hardly ever useful) Betriebssysteme / verteilte Systeme Introduction to Programming (1) 49 2.5 Repetition Variables A variable is (or can be viewed as) a named memory region that can be used to store data of a specific type int myvar Memory Address 100 101 102 103 Simple data types: int, short int, long int (signed and unsigned) float, double, char, bool Betriebssysteme / verteilte Systeme Introduction to Programming (1) 50

2.5 Repetition... Declaring variables All variables must be declared before they can be used Declaration: Type, followed by the name, followed by ; names can contain digits and, but must not start with a digit names are case-sensitive; certain names are reserved Example: unsigned long int myage; Declaring more than one variable at a time: unsigned int myage, myweight; // two unsigned ints long area, width, length; // three longs Initialization (= creation with initial assignment): int Width = 5; Betriebssysteme / verteilte Systeme Introduction to Programming (1) 51 2.5 Repetition... Constants Literal constants: 42, 0xFF, -23.5e16, true, a, "this is a string\n",... Symbolic constants: const unsigned short int studentsperclass = 15; Enumerated constants (enumerated types): enum Color { RED, GREEN, BLUE, BLACK, WHITE, CYAN, MAGENTA }; Color c = GREEN; Betriebssysteme / verteilte Systeme Introduction to Programming (1) 52