Appendix A Developing a C Program on the UNIX system

Size: px
Start display at page:

Download "Appendix A Developing a C Program on the UNIX system"

Transcription

1 Appendix A Developing a C Program on the UNIX system 1. Key in and save the program using vi - see Appendix B - (or some other editor) - ensure that you give the program file a name ending with.c - to indicate that it is a C program file. 2. Compile and link the program using cc <program name> This will produce two files: a) an object file with the same name as your original C program except that the extension will be.o b) an executable file (i.e. a program ready to run) called a.out. e.g. cc test.c compiles test.c producing an object program called test.o then automatically links the object program with relevant library files to produce a runnable program called a.out. 3. Run your program by typing a.out If you would prefer your executable program to be called something else then simply copy a.out to a new name. e.g. cp a.out test copies a.out to produce a runnable program called test. Alternatively, when compiling the program you can specify a particular name for the runnable program by using the -0 option followed by the desired name. e.g. cc -0 test test.c This will compile the program test.c producing - as before - an object file called test.o - and then link the program producing an executable file called test. So, the program can now be run simply by typing test. 265

2 Appendix B - Using vi One of the standard editors on the UNIX system is called vi. It is not particularly friendly, but you will quickly learn to use it - and can usually rely on it being available on most UNIX systems. Starting the vi Editor: vi <program name> Make up your own program name - but finish it with a suitable extension for the language you are using - which for C will be.c. e.g. vi test.c (allows you to key in a C program called test.c) Using vi Unlike a word processor you cannot simply start typing - but must tell the editor that you intend to do so by keying <escape> i. Every time you want to change what you are doing - say go from typing in text, to deleting text or saving the file - you will have to tell the editor that you intend to do so by pressing <escape> followed by the appropriate code. <ESC> I <ESC> x <ESC> dd <ESC> A <ESC> followed by an arrow key <ESC> :w <ESC> :w <program name> <ESC> :wq <ESC> :q! insert text delete a character (under the cursor). delete a line add text at the end of the line move around in the text save the program file save the program file with a new name save the program me and quit quit without saving Note that for the last four commands, when the colon (:) is pressed after the <escape> key, a colon will appear at the bottom ofthe screen ready for the w, wq or q! to be typed. Note that UNIXtreats capital letters andsmallletters as different. The vi editor has a wide range of additional commands which will generally be found in one of the manuals for your system. 266

3 Appendix C - The Binary System Our normal system of counting is denary. When we count past nine, we cannot represent 10 in a single digit so we 'carry' and use an additional digit. You could place column headings above a figure to help with additions, etc. (young children would probably do so). The column headings for the denary system would be: s..100s..los..is - so that, for example, the number 271 would be arranged in columns as: In other words, 271 means 2 lots of 100 plus 7lots of 10 plus 1 unit. We use this number system (also called Base 10 because the column headings grow larger - as they move leftwards - by being multiplied by 10) because we have 10 fingers. A computer, however, obviously does not have 10 fingers; it counts by switching electric currents ON (to represent 1) and OFF (to represent 0). If the computer needs to count further than one, it has to carryjust as we have to do if we want to count past 9. A computer, therefore, uses Base2 (i.e the Binary System) to count. It is possible to place column headings above a binary number - these are multiplied by 2 as they move leftwards: So - for example - the binary number would appear as: meaning 1 lot of lot of lot of 1 =25 denary. Think of all the binary digits as being electric lamps - each one representing a column heading. Ifa particular lamp's value is needed to help make up a number, the light is switched ON - otherwise the light is switched OFF. The digit 0 is used to indicate that the light is off - and 1 to indicate that it is on. 0 1 I I 1 ~ ~g- -g- ~ ~! -g--g ON ON ON ON =

4 Converting Binary numbersto Denary e.g. Convert Binary to Denary. Step 1. Arrange the numbers under binary column headings - so that the number finishes in the rightmost (Is) column. (To make the headings - start on the right with 1 - then keep multiplying by 2 as you move to the left - until there are enough headings to cover the whole number.) Step 2. Add all the headings from those columns which contain Is to get the final answer. So, = 51. (The 8 and 4 columns do not contain Is - so they are ignored. So, 1I 0011 in binary can be written as 51 in denary. Converting Denarynumbersto Binary e.g. convert39 to binary Step 1. Write down the binary column headings finishing on the left with the largest binary column heading which is less than the denary number that you are converting. In this case the largest heading which will go into 39 is Step 2. Subtract the largest heading from the number and write a I in that column (i.e. the 32 column in this case). Keep a note of the remainder Step 3. Repeat Step 2 with the remainder (in this case 7) and keep doing so until the whole number has been used up. So, the final answer is: So, 39 Denary can be written as 1001I 1 Binary. 268

5 Signed Binary Numbers Ifa variable is set up as signed (so that it can hold positive or negative values) the most significant bit (i.e, the largest column heading) is used to denote whether the number is positive or negative. Possibly the most common notation is two's complement. The most significant bit's column heading is made negative (all the other columns remain positive). So for a one-byte location, the headings will be: -128, 64,32, 16,8,4,2, 1. For a two-byte location (e.g. a typical integer) the headings are: ,16384,8192,4096,2048, 1014,512, ,64,32,16,8,4,2,1 As for unsigned numbers, the value of a number is found by adding all the column headings that are switched 0" 'g-~ !! -'g-! -'g-ft ON ON ON

6 AppendixD - The Hexadecimal System The Hexadecimal System (i.e. base 16) is a convenient shorthand for Binary and is used - for example - in machine code programming. The column headings for the hexadecimal system are: s 256s 16s Is (multiplying by 16 as you move left) So - for example hexadecimal would mean: I x x JU. =290 denary Because it is necessary to be able to count up to 15 in a single column without carrying - extra characters are needed to represent 10, II, 12, 13 and 14 as single digits; the letters A, B, C, D, E and F are used for this purpose. The Hexadecimal Digits are therefore: ABC D E F ConvertingBinary to Hexadecimal It is far simpler to convert binary to hexadecimal than to tum it into decimal. e.g. Convert BinaryintoHexadecimal. Step I Startingfrom the right, split the binary number into groups of four digits (quartets): llloolll Step 2 Again starting from the right place column headings above the binary digits - treating each quartetas separate Step 3 Now convert each quartet into a hexadecimal digit I 10 =14 Decimal =E Hexadecimal I 1 =7 Decimal =7 Hexadecimal Step 4 Place the hexadecimal digits together. So the answer is E7 Hexadecimal 270

7 Appendix E Character Codes Letters of the alphabet, punctuation marks, control codes - such as carriage return, and numeric digits ready to be sent immediately for display are represented by a character code. One of the most common is ASCIT(American Standard Code for Information Interchange). If a character held in ASCII is sent to an output device such as printer or VOU, the device will automatically output the appropriate characters shape. If, for example, a numeric digit is not held in a character code such as ASCII, it will have to be converted first before the device will recognise it. So, the command printj("%d", numl} will convert the value in numl from pure binary to a suitable character code (one code for each digit of the number) before sending it to the screen for display. However, the command printj("%c". numl) will simply send the binary pattern stored in numl to the screen - on the assumption that it contains a recognisable code for a single digit (or other character). Note that ASCII is a seven bit code, so the most significant bit of a byte (e.g. a character location) is not used. 271

8 ASCllCodes Character Binary Hex Character Binary Hex <NUL> 00000oo o 40 <SOH> A <STX> ()()()()()10 02 B <ETX> ()()()()()II 03 C <EOT> <ENQ> E <ACK> F <BEL> <BS> H <HT> <VT> OA J A <LF> OB K B <FF> OC L C <CR> M <SO> OE N E <SI> OF F <DLE> P <DCl> Q <DC2> R <DC3> S <DC4> T <NAK> U <SYN> IV <ETB> W <CAN> X <EM> Y <SUB> la Z SA <ESC> IB [ B <FS> lc \ C <OS> ) A <RS> IE E <US> IF SF ~ <SP> ! a " b #/ c $ d % e & f g ( h ) i A j A B k C C m E n E / F F p I q r s t u v w x y A z A B ( B < C I C ) > E E? F <DEL> F 272

9 Index #dejine 38 actual parameters 26 addition 11 address 130 Address arithmetic 133 ampersand 9 and 17 ar 221 argc 259 arguments 26, 226 argv 259 Arithmetic 11, 12 arithmetic shift 243 arithmetic signs 11 array 133,137,139,255 Array of pointers 259 Arrays - Single Dimensional 113, 114 Arrays - Two Dimensional 116, 117 Arrays of Pointers 139 Arrays of Pointers to Functions 255 Arrays of Strings 119 Arrays of Structures 121, 122 ASCn 271 Assignment 10, 106 Assignment Operators 12 atof 250 atoi 250 atol 250 automatic 37 binary stream 184 Binary System 267 Bit-fields 245, 247 Bitwise AND 239 Bitwise NOT 242 Bitwise Operators 239 Bitwise OR 240 Bitwise XOR 241 block 21,43,226 bounds checking 114 braces 3, 16, 19,21,43 break 18,44 buffer 50 buffered input 49 Buffered Keyboard Input 50 byte 124 case 18 cast 145,264 cc 215,265 Central Memory 124 char 6,56 character 6, 10 Character Codes 271 Character Type Functions 248 Circular Linked Lists 158 Command Line Arguments 259 comments 4 Comparing Pointers 135 compilation errors 2 Compile 265 compiler 1 Compiling and Linking Modules 215 Conditional Expressions 230 const 237 continue 44 Conversion of Data Types 261 ctype.h 248 Data Types 56 declaration 213 Decrementing 13 default 18 division II do..while 20, 52 Dynamic Memory Allocation 145, 147 end-of-string character 119 enum 40 EOF 193, 194, 198 Evaluating a Condition 52 executable file 265 exit 45 extern 216 extemallinkage 213 extemal variables 35 fclose 186, 189, 191, 194, 196, 199, 206 feof 189, 199 ferror 206 fgetc 198 field 184 FILE 185, 188, 191, 193, 196, 198 Files 184 Files - Handling Errors 205 Files - Reading Data from Disk one byte at a time using getc 198 Files - Reading Data from Disk using fread 188 Files - Reading Formatted Text from Disk using fscanf 193 Files - Storing Data on Disk using fwrite 185 Files - Writing Data to Disk - one byte at a time - using putc 196 Files - Writing Formatted Text to Disk using fprintf 191 float 6 float.h 58 floating point 6 fopen 185, 188, , 196, 198, 205 for

10 formal parameters 26 Formatting Output 46 fprintf 191, 207 fputc 196 fread 188,206 free 146, 153, 161, 170, 183 fseanf 193,207 fseek 200, 208 Functions 22,24,26,28,30,213 Functions - 32 fwrlte 186, 206 getc 198,208 getehar 49, 50 gets 9,50 Global Variables 35,216 goto 44 header file 222 header files 3, 5, 22 Hexadecimal 270 hierarchical 70, 83 Hierarchical Coding 83, 86, 88 if 52 if.. else 14, 15, 16 Implementing a Complex Program Design using Hierarchical Code 90 Implementing a Complex Program Design using In-line Code 79 Implementing a Design 70 Implementing a Program Design 93 in-line 70 In-line Coding 71, 75, 77 Incrementing 13 initialise 10 initialising 19 Input Format 48 int 6,56 integer 6 isalnum 248 isalpha 248 isdigit 248 islower 248 isprint 249 isspace 249 isupper 248 iteration 61,75,86 Keywords 5 label 44 Layout of a C Program 4 Left Shift 243 library 221 library files 3, 265 limits.h 58 link 265 Linked Lists 149 Local Variables 24,226 logic error 2 Logical Operators logical shift 243 long 56 long int 57 loop 19 machine code 1 macro 224, 226 Macros - using Arguments 226 mauoe 145, 147, ISO, 159, 168, 174 Mixing data types 263 Modular Programming 212 module 212 modulus 11 multiplication 11 Nested Structures 109, 111 newline 8 not 17 object file 265 Object Libraries 221 Operations on Structures 106 or 17 out-of-line 70, 83 parameter 106, 130, 137,257 Parameters 26 Passing Arrays as Parameter 137 Passing Function Addresses as Parameter 257 Passing Pointers as Parameters 130 pointer to a function 257 pointer variable 127, 128, 135 Pointers 126, 133, 139 Pointers and Arrays 133 Pointers to Arrays of Pointers 143 Pointers to Functions 251, 255 Pointers to Pointers 142 Pointers to Structures 131 preprocessor 224 print! 3,7,9,46,57 processor 236 Program Design 59 prototype 22 putc 196, 208 putchar 49 Queues 167 Random Files 200 record 184, 188 Recursion 34 recursive 179 register 236 Register Variables 236 relational expression 52 Relational Operators 14 remainder 11 reserved 5 return 3, 28, 44, 107 Right Shift 243 run-time error 2 scanf 7,9,48,50,57 selection 62,77,88

11 semi-colon 3 sequence 60, 71 short 56 short int 57 signed 56 Signed Binary Numbers 269 signed char 56 signed int 56 signed short int 57 sizeof 146 standard library 5 static 37,218 Static Local Variables 37 stdio.h 3 stdlib.h 45, 145,250 storage location 124 strcmp 42 strcpy 42 stream 184 string 106,113,119 String Functions 42 string.h 42 Strings 9, 10 strlen 42 struct 101, 104 structure 111,121,122,131,233,245 Structure Diagrams 59 Structure Types 104, 105 Structures 101, 102, 109 Subscripting Pointers 135 subtraction 11 switch 18 symbolic constant 38, 40 symbolic constants 58 tab 8 Test Plan 97, roo Testing Software 96 text format 184 text stream 184 tolower 249 toupper 249 Trees 173 typedef 228 unbuffered input 49 union 231,232,233 union type 231 Unions and Structures 233 UlVlX 1,215,265,266 unsigned 56 unsigned char 56 unsigned int 56 unsigned long int 57 unsigned short int 57 Using Pointers 128 Variables 6 vi 265,266 Vocabulary 5 void volatile 237 while 19,52 white space characters 50 word 124

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions Mr. Dave Clausen La Cañada High School Vocabulary Variable- A variable holds data that can change while the program

More information

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras

Numbers and Computers. Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras Numbers and Computers Debdeep Mukhopadhyay Assistant Professor Dept of Computer Sc and Engg IIT Madras 1 Think of a number between 1 and 15 8 9 10 11 12 13 14 15 4 5 6 7 12 13 14 15 2 3 6 7 10 11 14 15

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize two

More information

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case

o Echo the input directly to the output o Put all lower-case letters in upper case o Put the first letter of each word in upper case Overview of Today s Lecture Lecture 2: Character Input/Output in C Prof. David August COS 217 http://www.cs.princeton.edu/courses/archive/fall07/cos217/ Goals of the lecture o Important C constructs Program

More information

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS Chapter 1. 1.1. INTRODUCTION Digital computers have brought about the information age that we live in today. Computers are important tools because they can locate and process enormous amounts of information

More information

Data Representation and Binary Arithmetic. Lecture 2

Data Representation and Binary Arithmetic. Lecture 2 Data Representation and Binary Arithmetic Lecture 2 Computer Data Data is stored as binary; 0 s and 1 s Because two-state ( 0 & 1 ) logic elements can be manufactured easily Bit: binary digit (smallest

More information

Fundamentals of Programming (C)

Fundamentals of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamentals of Programming (C) Group 8 Lecturer: Vahid Khodabakhshi Lecture Number Systems Department of Computer Engineering Outline Numeral Systems

More information

Number System (Different Ways To Say How Many) Fall 2016

Number System (Different Ways To Say How Many) Fall 2016 Number System (Different Ways To Say How Many) Fall 2016 Introduction to Information and Communication Technologies CSD 102 Email: mehwish.fatima@ciitlahore.edu.pk Website: https://sites.google.com/a/ciitlahore.edu.pk/ict/

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations How do we represent data in a computer? At the lowest level, a computer is an electronic machine. works by controlling the flow of electrons Easy to recognize

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Original slides from Gregory Byrd, North Carolina State University Modified slides by Chris Wilcox, Colorado State University How do we represent data in a computer?!

More information

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices.

Bits and Bytes. Data Representation. A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices. Bits and Bytes 1 A binary digit or bit has a value of either 0 or 1; these are the values we can store in hardware devices. A byte is a sequence of 8 bits. A byte is also the fundamental unit of storage

More information

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

CPS 104 Computer Organization and Programming Lecture-2 : Data representations, CPS 104 Computer Organization and Programming Lecture-2 : Data representations, Sep. 1, 1999 Dietolf Ramm http://www.cs.duke.edu/~dr/cps104.html CPS104 Lec2.1 GK&DR Fall 1999 Data Representation Computers

More information

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University

Main Program. C Programming Notes. #include <stdio.h> main() { printf( Hello ); } Comments: /* comment */ //comment. Dr. Karne Towson University C Programming Notes Dr. Karne Towson University Reference for C http://www.cplusplus.com/reference/ Main Program #include main() printf( Hello ); Comments: /* comment */ //comment 1 Data Types

More information

SWEN-250 Personal SE. Introduction to C

SWEN-250 Personal SE. Introduction to C SWEN-250 Personal SE Introduction to C A Bit of History Developed in the early to mid 70s Dennis Ritchie as a systems programming language. Adopted by Ken Thompson to write Unix on a the PDP-11. At the

More information

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and

Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and Writing an ANSI C Program Getting Ready to Program A First Program Variables, Expressions, and Assignments Initialization The Use of #define and #include The Use of printf() and scanf() The Use of printf()

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers

Number Systems for Computers. Outline of Introduction. Binary, Octal and Hexadecimal numbers. Issues for Binary Representation of Numbers Outline of Introduction Administrivia What is computer architecture? What do computers do? Representing high level things in binary Data objects: integers, decimals, characters, etc. Memory locations (We

More information

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any from ee209 yet Follow the link from our class homepage

Reminder. Sign up for ee209 mailing list. Precept. If you haven t received any  from ee209 yet Follow the link from our class homepage EE209: C Examples 1 Reminder Sign up for ee209 mailing list If you haven t received any email from ee209 yet Follow the link from our class homepage Precept 7:00-8:15pm, every Wednesday 창의학습관 (Creative

More information

Chapter 3. Information Representation

Chapter 3. Information Representation Chapter 3 Information Representation Instruction Set Architecture APPLICATION LEVEL HIGH-ORDER LANGUAGE LEVEL ASSEMBLY LEVEL OPERATING SYSTEM LEVEL INSTRUCTION SET ARCHITECTURE LEVEL 3 MICROCODE LEVEL

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Original slides from Gregory Byrd, North Carolina State University Modified by Chris Wilcox, S. Rajopadhye Colorado State University How do we represent data

More information

C Examples. Goals of this Lecture. Overview of this Lecture

C Examples. Goals of this Lecture. Overview of this Lecture C Examples 1 Goals of this Lecture Help you learn about: The fundamentals of C Overall program structure, control statements, character I/O functions Deterministic finite state automata (DFA) Expectations

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

CSE 30 Fall 2012 Final Exam

CSE 30 Fall 2012 Final Exam Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5

APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5 APPENDIX A : KEYWORDS... 2 APPENDIX B : OPERATORS... 3 APPENDIX C : OPERATOR PRECEDENCE... 4 APPENDIX D : ESCAPE SEQUENCES... 5 APPENDIX E : ASCII CHARACTER SET... 6 APPENDIX F : USING THE GCC COMPILER

More information

CSE 30 Fall 2013 Final Exam

CSE 30 Fall 2013 Final Exam Login: cs30x Student ID Name Signature By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations Chapter 2 Bits, Data Types, and Operations Computer is a binary digital system. Digital system: finite number of symbols Binary (base two) system: has two states: 0 and 1 Basic unit of information is the

More information

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

EE 109 Unit 3. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL 3. 3. EE 9 Unit 3 Binary Representation Systems ANALOG VS. DIGITAL 3.3 3. Analog vs. Digital The analog world is based on continuous events. Observations can take on any (real) value. The digital world

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 2 Number Systems & Arithmetic Lecturer : Ebrahim Jahandar Some Parts borrowed from slides by IETC1011-Yourk University Common Number Systems System Base Symbols Used

More information

C PROGRAMMING. Characters and Strings File Processing Exercise

C PROGRAMMING. Characters and Strings File Processing Exercise C PROGRAMMING Characters and Strings File Processing Exercise CHARACTERS AND STRINGS A single character defined using the char variable type Character constant is an int value enclosed by single quotes

More information

6.096 Introduction to C++ January (IAP) 2009

6.096 Introduction to C++ January (IAP) 2009 MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Welcome to 6.096 Lecture

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013

Number Systems II MA1S1. Tristan McLoughlin. November 30, 2013 Number Systems II MA1S1 Tristan McLoughlin November 30, 2013 http://en.wikipedia.org/wiki/binary numeral system http://accu.org/index.php/articles/18 http://www.binaryconvert.com http://en.wikipedia.org/wiki/ascii

More information

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Prof. Gurindar Sohi TAs: Pradip Vallathol and Junaid Khalid Midterm Examination 1 In Class (50 minutes) Friday, September

More information

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent?

Data Representa5on. CSC 2400: Computer Systems. What kinds of data do we need to represent? CSC 2400: Computer Systems Data Representa5on What kinds of data do we need to represent? - Numbers signed, unsigned, integers, floating point, complex, rational, irrational, - Text characters, strings,

More information

Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1

Lecture 10 Arrays (2) and Strings. UniMAP SEM II - 11/12 DKT121 1 Lecture 10 Arrays (2) and Strings UniMAP SEM II - 11/12 DKT121 1 Outline 8.1 Passing Arrays to Function 8.2 Displaying Array in a Function 8.3 How Arrays are passed in a function call 8.4 Introduction

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

More information

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON

CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON CS/ECE 252: INTRODUCTION TO COMPUTER ENGINEERING UNIVERSITY OF WISCONSIN MADISON Prof. Gurindar Sohi TAs: Junaid Khalid and Pradip Vallathol Midterm Examination 1 In Class (50 minutes) Friday, September

More information

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example

Binary Numbers. The Basics. Base 10 Number. What is a Number? = Binary Number Example. Binary Number Example The Basics Binary Numbers Part Bit of This and a Bit of That What is a Number? Base Number We use the Hindu-Arabic Number System positional grouping system each position represents a power of Binary numbers

More information

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University Fundamental Data Types CSE 130: Introduction to Programming in C Stony Brook University Program Organization in C The C System C consists of several parts: The C language The preprocessor The compiler

More information

C mini reference. 5 Binary numbers 12

C mini reference. 5 Binary numbers 12 C mini reference Contents 1 Input/Output: stdio.h 2 1.1 int printf ( const char * format,... );......................... 2 1.2 int scanf ( const char * format,... );.......................... 2 1.3 char

More information

CSE 30 Winter 2014 Final Exam

CSE 30 Winter 2014 Final Exam Signature Login: cs30x Name Student ID By filling in the above and signing my name, I confirm I will complete this exam with the utmost integrity and in accordance with the Policy on Integrity of Scholarship.

More information

C Libraries. Bart Childs Complementary to the text(s)

C Libraries. Bart Childs Complementary to the text(s) C Libraries Bart Childs Complementary to the text(s) 2006 C was designed to make extensive use of a number of libraries. A great reference for student purposes is appendix B of the K&R book. This list

More information

Chapter 8 - Characters and Strings

Chapter 8 - Characters and Strings 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

More information

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL

EE 109 Unit 2. Analog vs. Digital. Analog vs. Digital. Binary Representation Systems ANALOG VS. DIGITAL EE 9 Unit Binary Representation Systems ANALOG VS. DIGITAL Analog vs. Digital The analog world is based on continuous events. Observations can take on any (real) value. The digital world is based on discrete

More information

Number Representations

Number Representations Simple Arithmetic [Arithm Notes] Number representations Signed numbers Sign-magnitude, ones and twos complement Arithmetic Addition, subtraction, negation, overflow MIPS instructions Logic operations MIPS

More information

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes

DATA REPRESENTATION. Data Types. Complements. Fixed Point Representations. Floating Point Representations. Other Binary Codes. Error Detection Codes 1 DATA REPRESENTATION Data Types Complements Fixed Point Representations Floating Point Representations Other Binary Codes Error Detection Codes 2 Data Types DATA REPRESENTATION Information that a Computer

More information

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME

CS341 *** TURN OFF ALL CELLPHONES *** Practice NAME CS341 *** TURN OFF ALL CELLPHONES *** Practice Final Exam B. Wilson NAME OPEN BOOK / OPEN NOTES: I GIVE PARTIAL CREDIT! SHOW ALL WORK! 1. Processor Architecture (20 points) a. In a Harvard architecture

More information

Midterm CSE 131 Winter 2012

Midterm CSE 131 Winter 2012 Login Name Signature _ Name Student ID Midterm CSE 131 Winter 2012 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (22 points) (29 points) (25 points) (34 points) (20 points) (18 points) Subtotal (148 points

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington

Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals. Alvin Valera. School of Engineering and Computer Science Victoria University of Wellington Week 1 / Lecture 2 8 March 2017 NWEN 241 C Fundamentals Alvin Valera School of Engineering and Computer Science Victoria University of Wellington Admin stuff People Course Coordinator Lecturer Alvin Valera

More information

CSCI 171 Chapter Outlines

CSCI 171 Chapter Outlines Contents CSCI 171 Chapter 1 Overview... 2 CSCI 171 Chapter 2 Programming Components... 3 CSCI 171 Chapter 3 (Sections 1 4) Selection Structures... 5 CSCI 171 Chapter 3 (Sections 5 & 6) Iteration Structures

More information

UNIT IV-2. The I/O library functions can be classified into two broad categories:

UNIT IV-2. The I/O library functions can be classified into two broad categories: UNIT IV-2 6.0 INTRODUCTION Reading, processing and writing of data are the three essential functions of a computer program. Most programs take some data as input and display the processed data, often known

More information

3.1. Unit 3. Binary Representation

3.1. Unit 3. Binary Representation 3.1 Unit 3 Binary Representation ANALOG VS. DIGITAL 3.2 3.3 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based on discrete

More information

ASSIGNMENT 5 TIPS AND TRICKS

ASSIGNMENT 5 TIPS AND TRICKS ASSIGNMENT 5 TIPS AND TRICKS linear-feedback shift registers Java implementation a simple encryption scheme http://princeton.edu/~cos26 Last updated on /26/7 : PM Goals OOP: implement a data type; write

More information

Midterm CSE 131 Winter 2014

Midterm CSE 131 Winter 2014 Student ID Login Name _ Name Signature Midterm CSE 131 Winter 2014 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (21 points) (36 points) (28 points) (16 points) (18 points) (20 points) Subtotal (139 points

More information

Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

More information

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes

CMSC 313 Lecture 03 Multiple-byte data big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes Multiple-byte data CMSC 313 Lecture 03 big-endian vs little-endian sign extension Multiplication and division Floating point formats Character Codes UMBC, CMSC313, Richard Chang 4-5 Chapter

More information

C: How to Program. Week /Mar/05

C: How to Program. Week /Mar/05 1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

More information

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014 Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas

More information

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants

2/29/2016. Definition: Computer Program. A simple model of the computer. Example: Computer Program. Data types, variables, constants Data types, variables, constants Outline.1 Introduction. Text.3 Memory Concepts.4 Naming Convention of Variables.5 Arithmetic in C.6 Type Conversion Definition: Computer Program A Computer program is a

More information

Model Viva Questions for Programming in C lab

Model Viva Questions for Programming in C lab Model Viva Questions for Programming in C lab Title of the Practical: Assignment to prepare general algorithms and flow chart. Q1: What is a flowchart? A1: A flowchart is a diagram that shows a continuous

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

The Binary Number System

The Binary Number System The Binary Number System Robert B. Heckendorn University of Idaho August 24, 2017 Numbers are said to be represented by a place-value system, where the value of a symbol depends on where it is... its place.

More information

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation

Unit 3. Analog vs. Digital. Analog vs. Digital ANALOG VS. DIGITAL. Binary Representation 3.1 3.2 Unit 3 Binary Representation ANALOG VS. DIGITAL 3.3 3.4 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based

More information

Simple Data Types in C. Alan L. Cox

Simple Data Types in C. Alan L. Cox Simple Data Types in C Alan L. Cox alc@rice.edu Objectives Be able to explain to others what a data type is Be able to use basic data types in C programs Be able to see the inaccuracies and limitations

More information

Chapter 2 Number System

Chapter 2 Number System Chapter 2 Number System Embedded Systems with ARM Cortext-M Updated: Tuesday, January 16, 2018 What you should know.. Before coming to this class Decimal Binary Octal Hex 0 0000 00 0x0 1 0001 01 0x1 2

More information

Oberon Data Types. Matteo Corti. December 5, 2001

Oberon Data Types. Matteo Corti. December 5, 2001 Oberon Data Types Matteo Corti corti@inf.ethz.ch December 5, 2001 1 Introduction This document is aimed at students without any previous programming experience. We briefly describe some data types of the

More information

UNIT- 3 Introduction to C++

UNIT- 3 Introduction to C++ UNIT- 3 Introduction to C++ C++ Character Sets: Letters A-Z, a-z Digits 0-9 Special Symbols Space + - * / ^ \ ( ) [ ] =!= . $, ; : %! &? _ # = @ White Spaces Blank spaces, horizontal tab, carriage

More information

EE 109 Unit 2. Binary Representation Systems

EE 109 Unit 2. Binary Representation Systems EE 09 Unit 2 Binary Representation Systems ANALOG VS. DIGITAL 2 3 Analog vs. Digital The analog world is based on continuous events. Observations can take on (real) any value. The digital world is based

More information

CSE 30 Winter 2009 Final Exam

CSE 30 Winter 2009 Final Exam Login: cs30x Student ID Name Signature CSE 30 Winter 2009 Final Exam 1. Number Systems / C Compiling Sequence (15 points) 2. Binary Addition/Condition Code Bits/Overflow Detection (12 points) 3. Branching

More information

Chapter 8 C Characters and Strings

Chapter 8 C Characters and Strings Chapter 8 C Characters and Strings Objectives of This Chapter To use the functions of the character handling library (). To use the string conversion functions of the general utilities library

More information

Final CSE 131 Winter 2010

Final CSE 131 Winter 2010 Student ID Login Name Name Signature _ Final CSE 131 Winter 2010 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 _ (26 points) _ (15 points) _ (36 points) _ (25 points) _

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 3 Constants, Variables, Data Types, And Operations Department of Computer Engineering

More information

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa)

Converting a Lowercase Letter Character to Uppercase (Or Vice Versa) Looping Forward Through the Characters of a C String A lot of C string algorithms require looping forward through all of the characters of the string. We can use a for loop to do that. The first character

More information

C: How to Program. Week /May/28

C: How to Program. Week /May/28 C: How to Program Week 14 2007/May/28 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions

More information

CSE 30 Spring 2006 Final Exam

CSE 30 Spring 2006 Final Exam cs30x_ Student ID Name _ Signature CSE 30 Spring 2006 Final Exam 1. Number Systems _ (15 points) 2. Binary Addition/Condition Code Bits/Overflow Detection _ (12 points) 3. Branching _ (18 points) 4. Bit

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

Do not start the test until instructed to do so!

Do not start the test until instructed to do so! Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted one-page formula sheet. No calculators or other electronic devices

More information

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are:

LESSON 1. A C program is constructed as a sequence of characters. Among the characters that can be used in a program are: LESSON 1 FUNDAMENTALS OF C The purpose of this lesson is to explain the fundamental elements of the C programming language. C like other languages has all alphabet and rules for putting together words

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

More information

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation

Introduction to Algorithms and Data Structures. Lecture 6 - Stringing Along - Character and String Manipulation Introduction to Algorithms and Data Structures Lecture 6 - Stringing Along - Character and String Manipulation What are Strings? Character data is stored as a numeric code that represents that particular

More information

CSE 30 Fall 2007 Final Exam

CSE 30 Fall 2007 Final Exam Login: cs30x Student ID Name Signature CSE 30 Fall 2007 Final Exam 1. Number Systems (25 points) 2. Binary Addition/Condition Code Bits/Overflow Detection (12 points) 3. Branching (19 points) 4. Bit Operations

More information

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme

2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme 2a. Codes and number systems (continued) How to get the binary representation of an integer: special case of application of the inverse Horner scheme repeated (integer) division by two. Example: What is

More information

Number Systems Base r

Number Systems Base r King Fahd University of Petroleum & Minerals Computer Engineering Dept COE 2 Fundamentals of Computer Engineering Term 22 Dr. Ashraf S. Hasan Mahmoud Rm 22-44 Ext. 724 Email: ashraf@ccse.kfupm.edu.sa 3/7/23

More information

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan

Introduction to C Programming. Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Introduction to C Programming Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Printing texts Adding 2 integers Comparing 2 integers C.E.,

More information

LESSON 4. The DATA TYPE char

LESSON 4. The DATA TYPE char LESSON 4 This lesson introduces some of the basic ideas involved in character processing. The lesson discusses how characters are stored and manipulated by the C language, how characters can be treated

More information

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program.

Experiment 3. TITLE Optional: Write here the Title of your program.model SMALL This directive defines the memory model used in the program. Experiment 3 Introduction: In this experiment the students are exposed to the structure of an assembly language program and the definition of data variables and constants. Objectives: Assembly language

More information

The following are the data types used in the C programming language:

The following are the data types used in the C programming language: Data Types in C The following are the data types used in the C programming language: Type Definition Size in memory void This particular type is used only in function declaration. boolean It stores false

More information

Midterm CSE 131 Fall 2014

Midterm CSE 131 Fall 2014 Login Name _ Signature Name _ Student ID Midterm CSE 131 Fall 2014 Page 1 Page 2 Page 3 Page 4 Page 5 (35 points) (30 points) (24 points) (24 points) (32 points) Subtotal (145 points = 100%) Page 6 Extra

More information

CSE 30 Spring 2007 Final Exam

CSE 30 Spring 2007 Final Exam Login: cs30x Student ID Name Signature CSE 30 Spring 2007 Final Exam 1. Number Systems (25 points) 2. Binary Addition/Condition Code Bits/Overflow Detection (12 points) 3. Branching (19 points) 4. Bit

More information

Positional Number System

Positional Number System Positional Number System A number is represented by a string of digits where each digit position has an associated weight. The weight is based on the radix of the number system. Some common radices: Decimal.

More information

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor.

This is great when speed is important and relatively few words are necessary, but Max would be a terrible language for writing a text editor. Dealing With ASCII ASCII, of course, is the numeric representation of letters used in most computers. In ASCII, there is a number for each character in a message. Max does not use ACSII very much. In the

More information

Computer Language. It is a systematical code for communication between System and user. This is in two categories.

Computer Language. It is a systematical code for communication between System and user. This is in two categories. ComputerWares There are 3 types of Computer wares. 1. Humanware: The person, who can use the system, is called 'Human Ware ". He is also called as "User". Users are in two types: i. Programmer: The person,

More information

Data types, variables, constants

Data types, variables, constants Data types, variables, constants Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic in C 2.6 Decision

More information

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010

CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011. MIDTERM EXAMINATION Spring 2010 CS201- Introduction to Programming Latest Solved Mcqs from Midterm Papers May 07,2011 Lectures 1-22 Moaaz Siddiq Asad Ali Latest Mcqs MIDTERM EXAMINATION Spring 2010 Question No: 1 ( Marks: 1 ) - Please

More information

Midterm CSE 131 Winter 2013

Midterm CSE 131 Winter 2013 Login Name Signature _ Name Student ID Midterm CSE 131 Winter 2013 Page 1 Page 2 Page 3 Page 4 Page 5 Page 6 (21 points) (21 points) (21 points) (23 points) (18 points) (24 points) Subtotal (128 points

More information

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents

AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session ) Contents AIR FORCE SCHOOL,BAMRAULI COMPUTER SCIENCE (083) CLASS XI Split up Syllabus (Session- 2017-18) Month July Contents UNIT 1: COMPUTER FUNDAMENTALS Evolution of computers; Basics of computer and its operation;

More information

Split up Syllabus (Session )

Split up Syllabus (Session ) Split up Syllabus (Session- -17) COMPUTER SCIENCE (083) CLASS XI Unit No. Unit Name Marks 1 COMPUTER FUNDAMENTALS 10 2 PROGRAMMING METHODOLOGY 12 3 INTRODUCTION TO C++ 14 4 PROGRAMMING IN C++ 34 Total

More information

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS

The Waite Group's. New. Primer Plus. Second Edition. Mitchell Waite and Stephen Prata SAMS The Waite Group's New Primer Plus Second Edition Mitchell Waite and Stephen Prata SAMS PUBLISHING A Division of Prentice Hall Computer Publishing 11711 North College, Carmel, Indiana 46032 USA Contents

More information