Topic 6A – The char Data Type. CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol.

Slides:



Advertisements
Similar presentations
Lecture 9: Character and String
Advertisements

Strings Testing for equality with strings.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
1 DATA ABSTRACTION: USER DEFINED TYPES AND THE CLASS.
Topic 9C – Multiple Dimension Arrays. CISC105 – Topic 9C Multiple Dimension Arrays A multiple dimension array is an array that has two or more dimensions.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
ECE 331 – Digital System Design
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
Introduction to Computers and Programming Lecture 7:
Scope and Casting. Scope Region of the program where a particular name can be referenced Formal parameters and local variables –can be accessed from within.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Program Elements We can now examine the core elements of programming (as implemented in Java) We focuse on: data types variable declaration and use, constants.
ECE122 L3: Expression Evaluation February 6, 2007 ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Programming Variables. Named area in the computer memory, intended to contain values of a certain kind (integers, real numbers, characters etc.) They.
MATH 224 – Discrete Mathematics
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
IT253: Computer Organization
Data Representation A series of eight bits is called a byte. A byte can be used to represent a number or a character. As you’ll see in the following table,
EXAMPLE 1 Writing Factors Members of the art club are learning to do calligraphy. Their first project is to make posters to display their new lettering.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
CISC105 – General Computer Science Class 9 – 07/03/2006.
VARIABLES, CONSTANTS, OPERATORS ANS EXPRESSION
 All C programs are made up of functions that perform operations on variables.  In this lecture we examine variables  Variables are the basic building.
ECE 301 – Digital Electronics Representation of Negative Numbers, Binary Arithmetic of Negative Numbers, and Binary Codes (Lecture #11) The slides included.
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
Unit 2 Test: Tues 11/3. ASCII / Unicode –Each letter, symbol, etc has a # value –See ascii table (in folder) –To convert a char into its ascii value,
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Programming in Java (COP 2250) Lecture 4 Chengyong Yang Fall, 2005.
Chapter 7 C supports two fundamentally different kinds of numeric types: (a) integer types - whole numbers (1) signed (2) unsigned (b) floating types –
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Road map char data type Reading –Liang 5: Chapter 2: 2.7.4; 2.9; –Liang 6: Chapter 2: 2.7.4; 2.9 –Liang 7: Chapter 2: 2.7.4; 2.9.
CSC Programming for Science Lecture 8: Character Functions.
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
Characters and Strings
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
INTRODUCTION TO ‘C’ PROGRAMMING BY Prof. P. PADMANABHAM M.Tech (AE), M.Tech(CS), Ph.D(CS)-FIETE, FIE Director Academics, Bharat Institute Of Engineering.
CMSC 202 Java Primer 1. July 24, 2007 Copyright © 2008 Pearson Addison-Wesley 2 A Sample Java Application.
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
ICS102 Lecture 1 : Expressions and Assignment King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer.
Arithmetic Operations (L05) * Arithmetic Operations * Variables * Declaration Statement * Software Development Procedure Problem Solving Using C Dr. Ming.
Number Systems. ASCII – American Standard Code for Information Interchange – Standard encoding scheme used to represent characters in binary format on.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
1.  Algorithm: 1. Read in the radius 2. Compute the area using the following formula: area = radius x radius x PI 3. Display the area 2.
Characters must also be encoded in binary. ASCII maps characters to numbers.
1.4 Representation of data in computer systems Character.
Fundamentals 2.
Programming and Data Structure
User Interaction and Variables
Binary 1 Basic conversions.
CMPT 201 if-else statement
EPSII 59:006 Spring 2004.
Multiple variables can be created in one declaration
Data Encoding Characters.
Unit-2 Objects and Classes
Computers & Programming Languages
Escape Sequences Some Java escape sequences: See Roses.java (page 68)
Numerical Data Types.
Coding Concepts (Data- Types)
Chapter 2: Java Fundamentals
C Programming Language
Boolean in C++ CSCE 121.
Section 6 Primitive Data Types
Presentation transcript:

Topic 6A – The char Data Type

CISC 105 – Topic 6A Characters are Numbers The char data type is really just a small (8 bit) number. As such, each symbol (character) is represented by a number. Typically, this representation is defined by a standard known as ASCII.

CISC 105 – Topic 6A Letters The upper-case letters go from ‘A’ which has ASCII value 65 through ‘Z’ which has value 90. Thus: ‘A’ < ‘B’ < ‘C’ < … < ‘X’ < ‘Y’ < ‘Z’ The lower-case letters go from ‘a’ which has ASCII value 97 though ‘z’ which has value 122. Thus: ‘a’ < ‘b’ < ‘c’ < … < ‘x’ < ‘y’ < ‘z’

CISC 105 – Topic 6A Letters Notice that the lower-case letters have larger ASCII values than upper-case letters. Thus: ‘A’ < ‘B’ < … < ‘Y’ < ‘Z’ < … < ‘a’ < ‘b’ < … < ‘x’ < ‘y’ < ‘z’ A program can compare char s using less-than, greater-than, etc… operators using the above relationships.

CISC 105 – Topic 6A Digits The digits go from ‘0’ which has ASCII value 48 through ‘9’ which has ASCII value 57. Thus: ‘0’ < ‘1’ < ‘2’ < … < ‘7’ < ‘8’ < ‘9’ Notice that each digit does NOT equal its ASCII value. Therefore 3 and ‘3’ are NOT the same.

CISC 105 – Topic 6A Other Characters All of the other characters (such as all have ASCII values as well. They can also be compared in the same manner as the letters and digits. However, as these characters do not relate as easily as the letters do to each other, this is more difficult.

CISC 105 – Topic 6A Integer Equivalence Notice that the char data type can also be casted, as the int and float type data types can be. Thus, (int)’E’ = 69 (int)’e’ = 101 (int)’3’ = 51

CISC 105 – Topic 6A Arithmetic Operations The char data type can also be subjected to arithmetic operations. Thus, ‘A’ + 3 = 68 = ‘D’ ‘h’ - 4 = 101 = ‘e’ ‘3’ * 1 = 51 = ‘3’