Chapter 8. Characters and Strings

Similar documents
ASSIGNMENT 5 TIPS AND TRICKS

Fundamentals of Programming (C)

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

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

1.1. INTRODUCTION 1.2. NUMBER SYSTEMS

Do not start the test until instructed to do so!

Lecture (09) x86 programming 8

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

Do not start the test until instructed to do so!

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

Chapter 2 Bits, Data Types, and Operations

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.

Data Representation and Binary Arithmetic. Lecture 2

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

Fundamentals of Programming

Oberon Data Types. Matteo Corti. December 5, 2001

Chapter 2 Bits, Data Types, and Operations

Chapter 3. Information Representation

Introduction to Decision Structures. Boolean & If Statements. Different Types of Decisions. Boolean Logic. Relational Operators

Do not start the test until instructed to do so!

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

Chapter 2 Bits, Data Types, and Operations

EXPERIMENT 8: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

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

Chapter 2 Number System

Review. Single Pixel Filters. Spatial Filters. Image Processing Applications. Thresholding Posterize Histogram Equalization Negative Sepia Grayscale

Number Representations

EXPERIMENT 7: Introduction to Universal Serial Asynchronous Receive Transmit (USART)

The Binary Number System

PureScan - ML1. Configuration Guide. Wireless Linear Imager Wireless Laser scanner - 1 -

Chapter 2 Bits, Data Types, and Operations

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

void mouseclicked() { // Called when the mouse is pressed and released // at the same mouse position }

Fundamental Data Types

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

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

Chapter 2 Bits, Data Types, and Operations

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

CSE-1520R Test #1. The exam is closed book, closed notes, and no aids such as calculators, cellphones, etc.

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

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?

Connecting UniOP to Datalogic Barcode Readers

Universal Asynchronous Receiver Transmitter Communication

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

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

5/17/2009. Digitizing Discrete Information. Ordering Symbols. Analog vs. Digital

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

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

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

Table of Contents Sleep Settings How to Configure the Scanner. 7 Chapter 2 System Setup

Variables and data types

1. Character/String Data, Expressions & Intrinsic Functions. Numeric Representation of Non-numeric Values. (CHARACTER Data Type), Part 1

Simple Data Types in C. Alan L. Cox

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

2D BARCODE SCANNER CA-SC-20200B

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, FALL 2012

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

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

User s Manual. Xi3000 Scanner. Table of Contents

Midterm CSE 131 Winter 2012

4/14/2015. Architecture of the World Wide Web. During this session we will discuss: Structure of the World Wide Web

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

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

Midterm CSE 131 Winter 2013

S-Series Sensor ASCII Protocol v8.1.0

Characters Lesson Outline

PS232. RS-232 to PS/2 Keyboard Port Adapter Part # SA0009 (Version 4.0) Copyright 2003 L3 Systems, Inc. Redmond

Under the Hood: Data Representation. Computer Science 104 Lecture 2

3.1. Unit 3. Binary Representation

First Data U.S. Debit Test Card Set. Version 1.20

Final Exam Practice Questions

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CPSC 213. Introduction to Computer Systems. Procedures and the Stack. Unit 1e

CSE 30 Fall 2013 Final Exam

KB232. PS/2 Keyboard RS-232 Adapter Part # SA0008 (Version 3.0) Copyright 2003 L3 Systems, Inc. Redmond

Configuration Manual PULSAR C CCD SCANNER. Table of Contents

Xi2000-BT Series Configuration Guide

n NOPn Unary no operation trap U aaa NOP Nonunary no operation trap i

Final CSE 131 Fall 2014

Midterm CSE 131 Winter 2014

Chapter 1. Hardware. Introduction to Computers and Programming. Chapter 1.2

PD1100 STAND-ALONE PROGRAMMING & USER S GUIDE. use the freedom

CMPSC 311- Introduction to Systems Programming Module: Strings

Menu & commands booklet FOR BAR CODE SCANNERS * *

NC-1200 BARCODE SCANNER. Configuration Guide - 1 -

Hardware. ( Not so hard really )

CSE 30 Spring 2006 Final Exam

BARCODE SCANNER. Configuration Guide - 1 -

+ Inheritance. n Superclass (base class) higher in the hierarchy. n Subclass (child class) lower in the hierarchy

Midterm CSE 131 Winter 2015

APPENDIX B. ASSEMBLER DIRECTIVE SUMMARY

Midterm CSE 131 Fall 2014

FD-011WU. 2D Barcode Reader User Guide V1.6CC

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 02, SPRING 2013

Watch the following for more announcements

Start Configuration. Chap.1 System Information. Set All default

Positional Number System

CSE 30 Spring 2007 Final Exam

User s Manual. Addendum to. Ranger Wedge Interface. Part No. 25-WEDGE-06A Ver. April 1999

Transcription:

Chapter 8 Characters and s OJECTIVES After you have read and studied this chapter, you should be able to Declare and manipulate data of the char data type. Write string processing programs using and uffer objects. Differentiate the and uffer classes and use the correct class in solving a given task. Distinguish the primitive and reference data types and show how the memory allocation between the two is different. Tell the difference between equality and equivalence testings for objects. Show, by using the state-of-memory diagrams, how objects are passed to methods and returned from methods. 1 of 12

TALE 8.1 ASCII Codes. 0 1 2 3 4 5 6 7 8 9 0 nul soh stx etx eot enq ack bel bs ht 10 lf vt ff cr so si dle dc1 dc2 dc3 20 cd4 nak syn etb can em sub esc fs gs 30 rs us sp! " # $ % & ' 40 ( ) * +, -. / 0 1 50 2 3 4 5 6 7 8 9 : ; 60 < = >? @ A C D E 70 F G H I J K L M N O 80 P Q R S T U V W X Y 90 Z [ \ ] ^ _ ` a b c 100 d e f g h i j k l m 110 n o p q r s t u v w 120 x y z { } ~ del FIGURE 8.1 An indexed expression is used to refer to individual characters in a string. = "Sumatra"; 0 1 2 3 4 5 6 S u m a t r a The variable refers to the whole string..charat(3) The method returns the character at position #3. 2 of 12

FIGURE 8.2 The taxonomy of data types. Data Type Primitive Reference byte short int long float double boolean char MainWindow Graphics Applet Messageox Outputox etc. FIGURE 8.3 Effect of assigning an integer value to a variable. num1 14 3 of 12

FIGURE 8.4 Effect of assigning values to integer variables. int num1, num2; after A is executed A num1 = 14; num2 = num1; num1 14 num1 += 5; num2 14 int num1, num2; after is executed num1 = 14; num2 = num1; num1 19 num1 += 5; num2 14 4 of 12

FIGURE 8.5 Effect of assigning a value to a variable. str is a variable of type, so its content is an address. str 1020 2036 This value 2036 is the address where the string data are actually stored. These are addresses of memory locations. 2036 J a 2040 k a 2044 r t We are assuming 4 bytes to a row. Each character requires 2 bytes, so each row can hold up to two characters. 2048 a FIGURE 8.6 Hypothetical memory management scheme for storing a value. str 1020 J k r a a a t 5 of 12

FIGURE 8.7 Memory shortage problem with the hypothetical memory management scheme. str 1020 I r 1024 i a 1028 n <space> This memory location already contains a value, so we don t have enough space to store the last three characters. 1032 J 1036 134590 1040 FIGURE 8.8 a y a A preferred style of diagram for representing memory allocation for a reference data type. str Jakarta str Jakarta Object Diagram Representation 6 of 12

FIGURE 8.9 Effect of assignment statements on reference data type. oth 1 and 2 are allocated memory, but no actual objects are created yet, so both are null. after A is executed A 1, 2; 1 = new (""); 2 = 1; 1 2 oth 1 and 2 are allocated memory, but no actual objects are created yet, so both are null. One object is created and assigned to 1; that is, 1 points to the object. after is executed 1, 2; 1 = new (""); 2 = 1; 1 2 Content of 1 (which is a reference to the object) is assigned to 2, making 2 also point to the same object. after C is executed C 1, 2; 1 = new (""); 2 = 1; 1 2 7 of 12

FIGURE 8.10 The difference between the equality test and the equals method. Case A: Referring to the same object. 1 2 1 == 2 is true 1.equals( 2 ) is true Note: If x == y is true, then x.equals(y) is also true. The reverse is not always true. Case : Referring to different objects having identical string values. 1 2 1 == 2 is false 1.equals( 2 ) is true Case C: Referring to different objects having different string values. 1 2 ali 1 == 2 is false 1.equals( 2 ) is false 8 of 12

FIGURE 8.11 How the memory space for parameters are allocated and deallocated. Execution Flow public void mymethod( uffer A struf ) { tester.mymethod( ); struf.setcharat(0, 'Y'); C D } at A before mymethod values are copied at struf The local variable does not exist before the method execution. The value of the argument, which is an address, is copied to the parameter. at D after mymethod after C is executed Yava Yava struf The parameter is erased. The argument points to the same (now modified) object. The content of the object referenced by the parameter is modified. 9 of 12

FIGURE 8.12 How a local copy of the passed object is created and manipulated. The original object will not change. Execution Flow public void mymethod( uffer A struf ) { tester.mymethod( ); uffer localcopy C = new uffer( struf.to() ); E localcopy.setcharat(0, 'Y'); } D values are copied at at A before mymethod struf after C is executed at E after mymethod struf local- Copy after D is executed A local copy is created and manipulated. Original object will not be affected. struf Yava local- Copy 10 of 12

FIGURE 8.13 How the reference data type is returned from the sayhi method. Execution Flow himsg = tester.sayhi( ); A public sayhi( ) { greeting; D greeting = "Hi, " + ; return greeting; } C at A before sayhi the address is copied at ill ill (sayhi) himsg himsg at D after sayhi after C is executed ill ill (sayhi) himsg Hi, ill himsg Hi, ill greeting The content of greeting is returned and assigned to himsg. 11 of 12

FIGURE 8.14 The object diagram for the EggyPeggy program. Note: and uffer objects are not shown here. EggyPeggyMain eggypeggy EggyPeggy main start mainwindow MainWindow responseox Responseox outputox Outputox inputox Inputox 12 of 12