As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!

Size: px
Start display at page:

Download "As previously noted, a byte can contain a numeric value in the range 0-255. Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets!"

Transcription

1 Encoding of alphanumeric and special characters As previously noted, a byte can contain a numeric value in the range Computers don't understand Latin, Cyrillic, Hindi, Arabic character sets! Alphanumeric and special characters of the Latin alphabet are stored in memory as integer values encoded using the ASCII code. (American standard code for the interchange of information). Other codes requiring 16 bits per character have been developed to support languages having large number of written symbols. A simple program for displaying the ASCII encoding scheme The correspondence between decimal, hexadecimal, and character representations can be readily generated via the following simple program. int main( int argc, char *argv[]) int c; c = ' '; /* Same as c = 32 or c = 0x20 */ while (c <= 'z') printf("%3d %02x %c \n", c, c, c); c = c + 1; 10

2 Output of the ASCII table generator class/210/examples ==> gcc -o p2 p2.c class/210/examples ==> p2 more ! " # $ % & ' ( ) 42 2a * 43 2b c, 45 2d e. 47 2f / : a : 59 3b ; 60 3c < 61 3d = 62 3e > 63 3f? A B : Y 90 5a Z 91 5b [ 92 5c \ 93 5d ] 94 5e ^ 95 5f _ ` a b : x y 122 7a z There are also a few special characters that follow z. 11

3 Control characters: The ASCII encodings between decimal 0 and 31 are used for to encode what are commonly called control characters. Control characters having decimal values in the range 1 through 26 can be entered from the keyboard by holding down the ctrl key while typing a letter in the set a through z. Some control characters have escaped code respresentations in C, but all may be written in octal. Dec Keystroke Name Escaped code 4 8 ctrl-d ctrl-h end of file backspace '\004' '\b' 9 ctrl-i tab '\t' 10 ctrl-j newline '\n' 12 ctrl-l page eject '\f' 13 ctrl-m carriage return '\r' 12

4 Formatted Output and Input Printing integer values: As previously noted integer values are stored in computer memory using a binary representation. To communicate the value of an integer to a human, it is necessary to produce the string of ASCII characters that correspond to the rendition of the integer in the Latin alphabet. For example the consider the byte This is the binary encoding of the hex number 0x94 which is the decimal number 9 * = 148. Therefore, if this number is to be rendered as a decimal number on a printer or display, three bytes corresponding to the ASCII encodings of 1, 4, and 8 must be sent to the printer or display. These bytes are expressed in hexadecimal as: In the C language, run time libraries provide functions that interface with the Operating System to provide this service. Some of these functions may actually be implemented as macros that call the actual RTL functions. The printf()function (actually a macro that converts to fprintf(stdout, ) ) is used to produce the ASCII encoding of an integer and send it to an output device or file. Format codes specify how you want to see the integer represented. %c Consider the integer to be the ASCII encoding of a character and render that character %d Produce the ASCII encoding of the integer expressed as a decimal number %x Produce the ASCII encoding of the integer expressed as a hexadecimal number %o Produce the ASCII encoding of the integer expressed as an octal number 13

5 Specifying field width These may be preceded by an optional field width specifier. The code %02x shown below forces the field to be padded with leading 0's if necessary to generate the specified field width. int main( int argc, char *argv[]) int x; int y = 78; x = 'A' x41 + '\n'; printf("x = %d \n", x); printf("y = %c %3d %02x %4o \n", y, y, y, y); /home/westall ==> gcc -o p1 p1.c /home/westall ==> p1 X = 270 Y = N 78 4e 116 The number of values printed by printf() is determined by the number of distinct format codes. 14

6 Output redirection The printf() function sends its output to a logical file commonly known as the standard outputor simply stdout. When a program is run in the Unix environment, the logical file stdout is by default associated with the screen being viewed by the person who started the program. The > operator may be used on the command line to cause the standard output to be redirected to a file: class/210/examples ==> p1 > p1.output A file created in this way may be subsequently viewed using the cat command (or edited using a text editor). class/210/examples ==> cat p1.output X = 270 Y = N 78 4e

7 Input of integer data When a human enters numeric data using the keyboard, the values passed to a program are the ASCII encodings of the keystrokes that were made. For example, when I type: bytes are produced by the keyboard. The hexadecimal encoding of these bytes is: E hex ascii To perform arithmetic using my number, it must be converted to interal floating point representation. The scanf() function is used to 1 - consume the ASCII encoding of a numeric value 2 - convert the ASCII string to the proper internal representation 3 - store the result in a memory location provided by the caller. As with printf(), a format code controls the process. The format code specifies both the input encoding and the desired type of value to be produced: %d string of decimal characters int %x string of hex characters unsigned int %o string of octal characters unsigned int %c ascii encoded character char %f floating point number in decimal float %lf floating point number in decimal double %e floating pt in scientific notation float Also as with printf() the number of values that scanf() will attempt to read is determined by the number of format codes provided. For each format code provided, it is mandatory that a variable be provided to hold the data that is read. 16

8 Specifying the variables to receive the values: It is extremely important to note that: the valueto be printed ins passed to printf() but the addressof the variable to receive the value must be passed to scanf() The & operator in C is the address of operator. Formatted input of integer values /* p3.c */ int main( int argc, char *argv[]) int a; int r; int b; r = scanf( %d %d, &a, &b); printf( Got %d items with values %d %d \n, r, a, b); 17

9 Care and feeding of input format specifiers Embedding of extra spaces and including '\n' in scanf() format strings can also lead to wierd behavior and should be avoided. Specification of field widths is dangerous unless you really know what you are doing. Effects of extra spaces in format specifier /* p3.c */ int main( int argc, char *argv[]) int a; int r; int b; r = scanf( %d %d, &a, &b); printf( Got %d items with values %d %d \n, r, a, b); If you enter only the two values that scanf() is expecting to find followed by enter nothing will happen. You will have to type control-d (which is the standard Unix end of file indicator). To get scanf() to return. class/210/examples ==> gcc -o p3 p3.c class/210/examples ==> p If you enter three values, it will not be necessary to enter control-d, but the third value will be ignored. class/210/examples ==> p Got 2 items with values 1 5 This bad behavior can be fixed by changing the function call to: r = scanf( %d %d, &a, &b); 18

10 Effect of invalid input If you accidentally enter a non-numeric value scanf() will abort and return you only 1 value. The value 4927 represents the uninitialized value of b. class/210/examples ==> p3 1 t 6 Got 1 items with values Pitfalls of field widths: It is legal to specify field widths to scanf() but usually dangerous to do so! class/210/examples ==> cat p4.c int main( int argc, char *argv[]) int a; int r; int b; r = scanf(" %2d %2d ", &a, &b); printf("got %d items with values %d %d \n", r, a, b); class/210/examples ==> p Got 2 items with values

11 Detecting end-of-file with scanf() scanf() returns the number of values it actually obtained (which may be less than the number of values requested). Therefore the proper way to test for end-of-file is to ensure that the number of values obtained was the nmber of values requested. /* p4b.c */ int main( int argc, char *argv[]) int a; int r; int b; while ((r = scanf("%d %d", &a, &b)) == 2) printf("got %d items with values %d %d \n", r, a, b); Input redirection Like the stdout the stdin may also be redirected. To redirect both stdin and stdout use: a.out < input.txt > output.txt when invoked in this manner when the program a.out reads from the stdin via scanf() or fscanf(stdin,.) the input will actually be read from a file named input.txt and any data written to the stdout will end up in the file output.txt. 20

12 The necessity of format conversion As stated previously, the %d format causes scanf() to convert the ASCII text representation of a number to an internal binary integer value. One might think it would be possible to avoid this and be able to deal with mixed alphabetic and numeric data by simply switching to the %c format. However, if we need to do arithmetic on what we read in, this approach does not work. /* p11c.c */ int main(void) char i, j, k; scanf("%c %c %c", &i, &j, &k); printf("the first input was %c \n", i); printf("the third input was %c \n", k); printf("their product is %c \n", i * k); class/210/examples ==> p11c 2 C 4 The first input was 2 The third input was 4 Their product is ( Why do we get ('' and not 8 for the answer? Since no format conversion is done the value stored in i is the ASCII code for the numeral 2 which is 0x32 = 50 Similarly the value stored in j is 0x34 = 52. When they are multiplied, the result is 50 x 52 = 2600 which is too large to be held in 8 bits. The 8 bit product is (2600 mod 256) (the remainder when 2600 is divided by 256). That value is = 40 = 0x28 which according to the ASCII table is the encoding of ('' 21

13 Floating point input and output The %e and %f format codes are used to print floating point numbers in scientific and decimal format. The l modifier should be used for doubles. Field size specificiation is of the form: field-width.number-of-digits-to-right-of-decimal int main( int argc, char *argv[]) float a; double b; float c; double d; a = ; b = e+03; scanf("%f %le", &c, &d); printf("a = %10.2f b = %8.4lf c = %f d = %8le \n", a, b, c, d); class/210/examples ==> gcc -o p5 p5.c class/210/examples ==> p e22 a = b = c = d = e+22 22

14 General Input and Output The C language itself defines no facility for I/O operations. I/O support is provided through two collections of mutually incomptible function libraries Low level I/O open(), close(), read(), write(), lseek(), ioctl() Standard library I/O fopen(), fclose() fprintf(), fscanf() conversion fgetc(), fputc() fgets(), fputs() fread(), fwrite(), fseek() - opening and closing files - field at a time with data - character (byte) at a time - line at a time - physical block at a time Our focus will be on the use of the standard I/O library: Function and constant definitions are obtained via #includefacility. To use the standard library functions: #include <errno.h> 23

15 Standard library I/O The functions operate on ADT's of type FILE * (which is defined in stdio.h). Three special FILE *'s are automatically opened when any process (program) starts: stdin Normally keyboard input (but may be redirected with < ) stdout Normally terminal output (but may be directed with > or 1> ) 1 stderr Normally terminal output (but may be directed with 2> ) Since these files are predeclared and preopend they must not be declared nor opened in your program! The following example shows how to open, read, and write disk files by name. In our assignments we will almost always read from stdin and write to stdout or stderr. 1 The 1> and 2> notation is supported by the sh family of shells incuding bash,but is not supported in csh, tcsh. 24

16 int main() FILE *f1; FILE *f2; int x; f1 = fopen( in.txt, r ); if (f1 == 0) perror( f1 failure ); exit(1); f2 = fopen( out.txt, w ); if (f2 == 0) perror( f2 failure ); exit(2); if (fscanf(f1, %d, &x)!= 1) perror( scanf failure ); exit(2); fprintf(f2, %d, x); fclose(f1); fclose(f2); 25

17 Examples of the use of p6 In this example, we have not yet created in.txt class/210/examples ==> gcc -o p6 p6.c class/210/examples ==> p6 f1 failure:: No such file or directory cat: in.txt: No such file or directory Here, in.txt is created with the cat command: class/210/examples ==> cat > in.txt 99 Now if we rerun p6 and cat out.txt we obtain the correct answer class/210/examples ==> p6 class/210/examples ==> cat out.txt 99 Note: The scanf() and printf() functions are actually macros or abbreviations for: fscanf(stdin,...) and (stdout,...) 26

18 Character at a time input and output The fgetc() function can be used to read an I/O stream one byte at a time. The fputc() function can be used to write an I/O stream one byte at a time. Here is an example of how to build a cat command using the two functions. The p10 program is being used here to copy its own source code from standard input to output. class/210/examples ==> p10 < p10.c /* p10.c */ main() int c; while ((c = fgetc(stdin)) > 0) fputc(c, stdout); While fputc() and fgetc() are fine for building interactive applications, they are very inefficient and should never be used for reading or writing a large volume of data such as a photographic image file. 27

19 Line at a time input and character string output. The fgets(buffer_address, buf_size, file) function can be used to read from a stream until either: 1 - a newline character '\n' = 10 = 0x0a is encountered or 2 - the specified number of characters - 1 has been read or 3 - end of file is reached. There is no string data type in C, but a standard convention is that a string is an array of characters in which the end is of the string is marked by the presence of a byte which has the value binary (sometimes called the NULL character). fgets() will append the NULL character to whatever it reads in. Since fgets() will read in multiple characters it is not possible to assign what it reads to a single variable of type char. Thus a pointer to a buffermust be passed (as was the case with scanf()). The fputs() function writes a NULL terminated string to a stream (after stripping off the NULL). The following example is yet another cat program, but this one works one line at a time. class/210/examples ==> p11 < p11.c 2> countem /* p11.c */ #include <string.h> main() unsigned char *buff = NULL; int line = 0; buff = malloc(1024); // alloc storage to hold data if (buff == 0) exit(1); 28

20 while (fgets(buff, 1024, stdin)!= 0) fputs(buff, stdout); fprintf(stderr, "%d %d \n", line, strlen(buff)); line += 1; free(buff); // release the storage malloc allocated Here buff is declared a pointer and the storage which will hold the data is allocated with malloc() Alternatively we could have declared unsigned char buff[1024] and not used malloc() Here is the output that went to the standard error. Note that each line that appeared empty has length 1 (the newline character itself) and the lines that appear to have length 1 actually have length 2. class/210/examples ==> cat countem

File Handling. What is a file?

File Handling. What is a file? File Handling 1 What is a file? A named collection of data, stored in secondary storage (typically). Typical operations on files: Open Read Write Close How is a file stored? Stored as sequence of bytes,

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters

ASCII Encoding. The char Type. Manipulating Characters. Manipulating Characters The char Type ASCII Encoding The C char type stores small integers. It is usually 8 bits. char variables guaranteed to be able to hold integers 0.. +127. char variables mostly used to store characters

More information

System Calls and Standard I/O

System Calls and Standard I/O System Calls and Standard I/O Professor Jennifer Rexford http://www.cs.princeton.edu/~jrex 1 Goals of Today s Class System calls o How a user process contacts the Operating System o For advanced services

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)

More information

The programming language C. sws1 1

The programming language C. sws1 1 The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan

More information

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu

C / C++ and Unix Programming. Materials adapted from Dan Hood and Dianna Xu C / C++ and Unix Programming Materials adapted from Dan Hood and Dianna Xu 1 C and Unix Programming Today s goals ú History of C ú Basic types ú printf ú Arithmetic operations, types and casting ú Intro

More information

Chapter 4: Computer Codes

Chapter 4: Computer Codes Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence 36 Slide 2/30 Data

More information

So far we have considered only numeric processing, i.e. processing of numeric data represented

So far we have considered only numeric processing, i.e. processing of numeric data represented Chapter 4 Processing Character Data So far we have considered only numeric processing, i.e. processing of numeric data represented as integer and oating point types. Humans also use computers to manipulate

More information

Simple C Programs. Goals for this Lecture. Help you learn about:

Simple C Programs. Goals for this Lecture. Help you learn about: Simple C Programs 1 Goals for this Lecture Help you learn about: Simple C programs Program structure Defining symbolic constants Detecting and reporting failure Functionality of the gcc command Preprocessor,

More information

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

2 ASCII TABLE (DOS) 3 ASCII TABLE (Window) 1 ASCII TABLE 2 ASCII TABLE (DOS) 3 ASCII TABLE (Window) 4 Keyboard Codes The Diagram below shows the codes that are returned when a key is pressed. For example, pressing a would return 0x61. If it is

More information

5 Arrays and Pointers

5 Arrays and Pointers 5 Arrays and Pointers 5.1 One-dimensional arrays Arrays offer a convenient way to store and access blocks of data. Think of arrays as a sequential list that offers indexed access. For example, a list of

More information

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

2011, The McGraw-Hill Companies, Inc. Chapter 3 Chapter 3 3.1 Decimal System The radix or base of a number system determines the total number of different symbols or digits used by that system. The decimal system has a base of 10 with the digits 0 through

More information

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

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

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

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C Embedded Systems A Review of ANSI C and Considerations for Embedded C Programming Dr. Jeff Jackson Lecture 2-1 Review of ANSI C Topics Basic features of C C fundamentals Basic data types Expressions Selection

More information

Numbering Systems. InThisAppendix...

Numbering Systems. InThisAppendix... G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal

More information

Module 816. File Management in C. M. Campbell 1993 Deakin University

Module 816. File Management in C. M. Campbell 1993 Deakin University M. Campbell 1993 Deakin University Aim Learning objectives Content After working through this module you should be able to create C programs that create an use both text and binary files. After working

More information

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

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal. Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must be able to handle more than just values for real world problems

More information

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

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8 ECE Department Summer LECTURE #5: Number Systems EEL : Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz Decimal Number System: -Our standard number system is base, also

More information

Member Functions of the istream Class

Member Functions of the istream Class Member Functions of the istream Class The extraction operator is of limited use because it always uses whitespace to delimit its reads of the input stream. It cannot be used to read those whitespace characters,

More information

Number Representation

Number Representation Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur Topics to be Discussed How are numeric data

More information

Lecture 16: System-Level I/O

Lecture 16: System-Level I/O CSCI-UA.0201-003 Computer Systems Organization Lecture 16: System-Level I/O Mohamed Zahran (aka Z) mzahran@cs.nyu.edu http://www.mzahran.com Some slides adapted (and slightly modified) from: Clark Barrett

More information

Pemrograman Dasar. Basic Elements Of Java

Pemrograman Dasar. Basic Elements Of Java Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle

More information

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

EE 261 Introduction to Logic Circuits. Module #2 Number Systems EE 261 Introduction to Logic Circuits Module #2 Number Systems Topics A. Number System Formation B. Base Conversions C. Binary Arithmetic D. Signed Numbers E. Signed Arithmetic F. Binary Codes Textbook

More information

Base Conversion written by Cathy Saxton

Base Conversion written by Cathy Saxton Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,

More information

Systems I: Computer Organization and Architecture

Systems I: Computer Organization and Architecture Systems I: Computer Organization and Architecture Lecture 2: Number Systems and Arithmetic Number Systems - Base The number system that we use is base : 734 = + 7 + 3 + 4 = x + 7x + 3x + 4x = x 3 + 7x

More information

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

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T) Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating

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

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Digital Logic II May, I before starting the today s lecture

More information

plc numbers - 13.1 Encoded values; BCD and ASCII Error detection; parity, gray code and checksums

plc numbers - 13.1 Encoded values; BCD and ASCII Error detection; parity, gray code and checksums plc numbers - 3. Topics: Number bases; binary, octal, decimal, hexadecimal Binary calculations; s compliments, addition, subtraction and Boolean operations Encoded values; BCD and ASCII Error detection;

More information

ASCII Code. Numerous codes were invented, including Émile Baudot's code (known as Baudot

ASCII Code. Numerous codes were invented, including Émile Baudot's code (known as Baudot ASCII Code Data coding Morse code was the first code used for long-distance communication. Samuel F.B. Morse invented it in 1844. This code is made up of dots and dashes (a sort of binary code). It was

More information

Binary Representation

Binary Representation Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must tbe able to handle more than just values for real world problems

More information

/* File: blkcopy.c. size_t n

/* File: blkcopy.c. size_t n 13.1. BLOCK INPUT/OUTPUT 505 /* File: blkcopy.c The program uses block I/O to copy a file. */ #include main() { signed char buf[100] const void *ptr = (void *) buf FILE *input, *output size_t

More information

Characters & Strings Lesson 1 Outline

Characters & Strings Lesson 1 Outline Outline 1. Outline 2. Numeric Encoding of Non-numeric Data #1 3. Numeric Encoding of Non-numeric Data #2 4. Representing Characters 5. How Characters Are Represented #1 6. How Characters Are Represented

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

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

The string of digits 101101 in the binary number system represents the quantity Data Representation Section 3.1 Data Types Registers contain either data or control information Control information is a bit or group of bits used to specify the sequence of command signals needed for

More information

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands C Programming for Embedded Microcontrollers Warwick A. Smith Elektor International Media BV Postbus 11 6114ZG Susteren The Netherlands 3 the Table of Contents Introduction 11 Target Audience 11 What is

More information

System Calls Related to File Manipulation

System Calls Related to File Manipulation KING FAHD UNIVERSITY OF PETROLEUM AND MINERALS Information and Computer Science Department ICS 431 Operating Systems Lab # 12 System Calls Related to File Manipulation Objective: In this lab we will be

More information

Simple Image File Formats

Simple Image File Formats Chapter 2 Simple Image File Formats 2.1 Introduction The purpose of this lecture is to acquaint you with the simplest ideas in image file format design, and to get you ready for this week s assignment

More information

Section 1.4 Place Value Systems of Numeration in Other Bases

Section 1.4 Place Value Systems of Numeration in Other Bases Section.4 Place Value Systems of Numeration in Other Bases Other Bases The Hindu-Arabic system that is used in most of the world today is a positional value system with a base of ten. The simplest reason

More information

Useful Number Systems

Useful Number Systems Useful Number Systems Decimal Base = 10 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9} Binary Base = 2 Digit Set = {0, 1} Octal Base = 8 = 2 3 Digit Set = {0, 1, 2, 3, 4, 5, 6, 7} Hexadecimal Base = 16 = 2

More information

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 INTRODUCTION TO DIGITAL LOGIC

Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 INTRODUCTION TO DIGITAL LOGIC Levent EREN levent.eren@ieu.edu.tr A-306 Office Phone:488-9882 1 Number Systems Representation Positive radix, positional number systems A number with radix r is represented by a string of digits: A n

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

PHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery

PHP Debugging. Draft: March 19, 2013 2013 Christopher Vickery PHP Debugging Draft: March 19, 2013 2013 Christopher Vickery Introduction Debugging is the art of locating errors in your code. There are three types of errors to deal with: 1. Syntax errors: When code

More information

Embedded Systems Design Course Applying the mbed microcontroller

Embedded Systems Design Course Applying the mbed microcontroller Embedded Systems Design Course Applying the mbed microcontroller Memory and data management These course notes are written by R.Toulson (Anglia Ruskin University) and T.Wilmshurst (University of Derby).

More information

Variables, Constants, and Data Types

Variables, Constants, and Data Types Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight

More information

Giving credit where credit is due

Giving credit where credit is due JDEP 284H Foundations of Computer Systems System-Level I/O Dr. Steve Goddard goddard@cse.unl.edu Giving credit where credit is due Most of slides for this lecture are based on slides created by Drs. Bryant

More information

6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10

6 3 4 9 = 6 10 + 3 10 + 4 10 + 9 10 Lesson The Binary Number System. Why Binary? The number system that you are familiar with, that you use every day, is the decimal number system, also commonly referred to as the base- system. When you

More information

The use of binary codes to represent characters

The use of binary codes to represent characters The use of binary codes to represent characters Teacher s Notes Lesson Plan x Length 60 mins Specification Link 2.1.4/hi Character Learning objective (a) Explain the use of binary codes to represent characters

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Lecture 25 Systems Programming Process Control

Lecture 25 Systems Programming Process Control Lecture 25 Systems Programming Process Control A process is defined as an instance of a program that is currently running. A uni processor system or single core system can still execute multiple processes

More information

Unix the Bare Minimum

Unix the Bare Minimum Unix the Bare Minimum Norman Matloff September 27, 2005 c 2001-2005, N.S. Matloff Contents 1 Purpose 2 2 Shells 2 3 Files and Directories 4 3.1 Creating Directories.......................................

More information

arrays C Programming Language - Arrays

arrays C Programming Language - Arrays arrays So far, we have been using only scalar variables scalar meaning a variable with a single value But many things require a set of related values coordinates or vectors require 3 (or 2, or 4, or more)

More information

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

Keywords are identifiers having predefined meanings in C programming language. The list of keywords used in standard C are : unsigned void 1. Explain C tokens Tokens are basic building blocks of a C program. A token is the smallest element of a C program that is meaningful to the compiler. The C compiler recognizes the following kinds of

More information

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.

Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved. 1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

More information

CSI 333 Lecture 1 Number Systems

CSI 333 Lecture 1 Number Systems CSI 333 Lecture 1 Number Systems 1 1 / 23 Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2...

More information

Computer Science 281 Binary and Hexadecimal Review

Computer Science 281 Binary and Hexadecimal Review Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two

More information

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

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals: Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger

More information

The Answer to the 14 Most Frequently Asked Modbus Questions

The Answer to the 14 Most Frequently Asked Modbus Questions Modbus Frequently Asked Questions WP-34-REV0-0609-1/7 The Answer to the 14 Most Frequently Asked Modbus Questions Exactly what is Modbus? Modbus is an open serial communications protocol widely used in

More information

Japanese Character Printers EPL2 Programming Manual Addendum

Japanese Character Printers EPL2 Programming Manual Addendum Japanese Character Printers EPL2 Programming Manual Addendum This addendum contains information unique to Zebra Technologies Japanese character bar code printers. The Japanese configuration printers support

More information

The Hexadecimal Number System and Memory Addressing

The Hexadecimal Number System and Memory Addressing APPENDIX C The Hexadecimal Number System and Memory Addressing U nderstanding the number system and the coding system that computers use to store data and communicate with each other is fundamental to

More information

Operating Systems. Privileged Instructions

Operating Systems. Privileged Instructions Operating Systems Operating systems manage processes and resources Processes are executing instances of programs may be the same or different programs process 1 code data process 2 code data process 3

More information

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

The Linux Operating System and Linux-Related Issues

The Linux Operating System and Linux-Related Issues Review Questions: The Linux Operating System and Linux-Related Issues 1. Explain what is meant by the term copyleft. 2. In what ways is the Linux operating system superior to the UNIX operating system

More information

Secrets of printf. 1 Background. 2 Simple Printing. Professor Don Colton. Brigham Young University Hawaii. 2.1 Naturally Special Characters

Secrets of printf. 1 Background. 2 Simple Printing. Professor Don Colton. Brigham Young University Hawaii. 2.1 Naturally Special Characters Secrets of Professor Don Colton Brigham Young University Hawaii is the C language function to do formatted printing. The same function is also available in PERL. This paper explains how works, and how

More information

Programming languages C

Programming languages C INTERNATIONAL STANDARD ISO/IEC 9899:1999 TECHNICAL CORRIGENDUM 2 Published 2004-11-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE

More information

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

1. Boolean Data Type & Expressions Outline. Basic Data Types. Numeric int float Non-numeric char Boolean Data Type & Expressions Outline. Boolean Data Type & Expressions Outline 2. Basic Data Types 3. C Boolean Data Types: char or int/ Boolean Declaration 4. Boolean or Character? 5. Boolean Literal

More information

Basics of I/O Streams and File I/O

Basics of I/O Streams and File I/O Basics of This is like a cheat sheet for file I/O in C++. It summarizes the steps you must take to do basic I/O to and from files, with only a tiny bit of explanation. It is not a replacement for reading

More information

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations

Chapter Binary, Octal, Decimal, and Hexadecimal Calculations Chapter 5 Binary, Octal, Decimal, and Hexadecimal Calculations This calculator is capable of performing the following operations involving different number systems. Number system conversion Arithmetic

More information

Project 2: Bejeweled

Project 2: Bejeweled Project 2: Bejeweled Project Objective: Post: Tuesday March 26, 2013. Due: 11:59PM, Monday April 15, 2013 1. master the process of completing a programming project in UNIX. 2. get familiar with command

More information

COMPSCI 210. Binary Fractions. Agenda & Reading

COMPSCI 210. Binary Fractions. Agenda & Reading COMPSCI 21 Binary Fractions Agenda & Reading Topics: Fractions Binary Octal Hexadecimal Binary -> Octal, Hex Octal -> Binary, Hex Decimal -> Octal, Hex Hex -> Binary, Octal Animation: BinFrac.htm Example

More information

Streaming Lossless Data Compression Algorithm (SLDC)

Streaming Lossless Data Compression Algorithm (SLDC) Standard ECMA-321 June 2001 Standardizing Information and Communication Systems Streaming Lossless Data Compression Algorithm (SLDC) Phone: +41 22 849.60.00 - Fax: +41 22 849.60.01 - URL: http://www.ecma.ch

More information

Lecture 11: Number Systems

Lecture 11: Number Systems Lecture 11: Number Systems Numeric Data Fixed point Integers (12, 345, 20567 etc) Real fractions (23.45, 23., 0.145 etc.) Floating point such as 23. 45 e 12 Basically an exponent representation Any number

More information

Boolean Data Outline

Boolean Data Outline 1. Boolean Data Outline 2. Data Types 3. C Boolean Data Type: char or int 4. C Built-In Boolean Data Type: bool 5. bool Data Type: Not Used in CS1313 6. Boolean Declaration 7. Boolean or Character? 8.

More information

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

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic: Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents

More information

Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1

Binary Number System. 16. Binary Numbers. Base 10 digits: 0 1 2 3 4 5 6 7 8 9. Base 2 digits: 0 1 Binary Number System 1 Base 10 digits: 0 1 2 3 4 5 6 7 8 9 Base 2 digits: 0 1 Recall that in base 10, the digits of a number are just coefficients of powers of the base (10): 417 = 4 * 10 2 + 1 * 10 1

More information

Chapter One Introduction to Programming

Chapter One Introduction to Programming Chapter One Introduction to Programming 1-1 Algorithm and Flowchart Algorithm is a step-by-step procedure for calculation. More precisely, algorithm is an effective method expressed as a finite list of

More information

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment .i.-' `-. i..' `/ \' _`.,-../ o o \.' ` ( / \ ) \\\ (_.'.'"`.`._) /// \\`._(..: :..)_.'// \`. \.:-:. /.'/ `-i-->..

More information

Version 1.5 Satlantic Inc.

Version 1.5 Satlantic Inc. SatCon Data Conversion Program Users Guide Version 1.5 Version: 1.5 (B) - March 09, 2011 i/i TABLE OF CONTENTS 1.0 Introduction... 1 2.0 Installation... 1 3.0 Glossary of terms... 1 4.0 Getting Started...

More information

1 Description of The Simpletron

1 Description of The Simpletron Simulating The Simpletron Computer 50 points 1 Description of The Simpletron In this assignment you will write a program to simulate a fictional computer that we will call the Simpletron. As its name implies

More information

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

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program. Name: Class: Date: Exam #1 - Prep True/False Indicate whether the statement is true or false. 1. Programming is the process of writing a computer program in a language that the computer can respond to

More information

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

Machine Architecture and Number Systems. Major Computer Components. Schematic Diagram of a Computer. The CPU. The Bus. Main Memory. 1 Topics Machine Architecture and Number Systems Major Computer Components Bits, Bytes, and Words The Decimal Number System The Binary Number System Converting from Decimal to Binary Major Computer Components

More information

UNIX, Shell Scripting and Perl Introduction

UNIX, Shell Scripting and Perl Introduction UNIX, Shell Scripting and Perl Introduction Bart Zeydel 2003 Some useful commands grep searches files for a string. Useful for looking for errors in CAD tool output files. Usage: grep error * (looks for

More information

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

This section describes how LabVIEW stores data in memory for controls, indicators, wires, and other objects. Application Note 154 LabVIEW Data Storage Introduction This Application Note describes the formats in which you can save data. This information is most useful to advanced users, such as those using shared

More information

Chapter 1: Digital Systems and Binary Numbers

Chapter 1: Digital Systems and Binary Numbers Chapter 1: Digital Systems and Binary Numbers Digital age and information age Digital computers general purposes many scientific, industrial and commercial applications Digital systems telephone switching

More information

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com)

Advanced Bash Scripting. Joshua Malone (jmalone@ubergeeks.com) Advanced Bash Scripting Joshua Malone (jmalone@ubergeeks.com) Why script in bash? You re probably already using it Great at managing external programs Powerful scripting language Portable and version-stable

More information

Decimal to Binary Conversion

Decimal to Binary Conversion Decimal to Binary Conversion A tool that makes the conversion of decimal values to binary values simple is the following table. The first row is created by counting right to left from one to eight, for

More information

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs

3/13/2012. Writing Simple C Programs. ESc101: Decision making using if-else and switch statements. Writing Simple C Programs Writing Simple C Programs ESc101: Decision making using if- and switch statements Instructor: Krithika Venkataramani Semester 2, 2011-2012 Use standard files having predefined instructions stdio.h: has

More information

How To Write Portable Programs In C

How To Write Portable Programs In C Writing Portable Programs COS 217 1 Goals of Today s Class Writing portable programs in C Sources of heterogeneity Data types, evaluation order, byte order, char set, Reading period and final exam Important

More information

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

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand: Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of

More information

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

Computers. Hardware. The Central Processing Unit (CPU) CMPT 125: Lecture 1: Understanding the Computer Computers CMPT 125: Lecture 1: Understanding the Computer Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 A computer performs 2 basic functions: 1.

More information

DOS Command Reference

DOS Command Reference DOS Command Reference Introduction Some course material on the Teaching Network may still use the command line operating system called DOS (Disk Operating System). This requires the user to type specific

More information

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions

Phys4051: C Lecture 2 & 3. Comment Statements. C Data Types. Functions (Review) Comment Statements Variables & Operators Branching Instructions Phys4051: C Lecture 2 & 3 Functions (Review) Comment Statements Variables & Operators Branching Instructions Comment Statements! Method 1: /* */! Method 2: // /* Single Line */ //Single Line /* This comment

More information

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012 Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about

More information

Binary Numbers. Binary Octal Hexadecimal

Binary Numbers. Binary Octal Hexadecimal Binary Numbers Binary Octal Hexadecimal Binary Numbers COUNTING SYSTEMS UNLIMITED... Since you have been using the 10 different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 all your life, you may wonder how

More information

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

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

More information

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++)

Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) Lab 2 - CMPS 1043, Computer Science I Introduction to File Input/Output (I/O) Projects and Solutions (C++) (Revised from http://msdn.microsoft.com/en-us/library/bb384842.aspx) * Keep this information to

More information