Agenda ASCII char N int Character class char N String Bitwise operators homework.

Slides:



Advertisements
Similar presentations
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.
Advertisements

Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
C Strings. The char Data Type for Storing Characters The char data type can is used to declare a variable that can hold a single character. Examples:
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Advanced Topics Object-Oriented Programming Using C++ Second Edition 13.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9: Characters * Character primitives * Character Wrapper class.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
Data types and variables
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
Chapter 2 Data Types, Declarations, and Displays
JavaScript, Third Edition
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
String Escape Sequences
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Representing text Each of different symbol on the text (alphabet letter) is assigned a unique bit patterns the text is then representing as.
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.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Chapter 3: Data Types and Operators JavaScript - Introductory.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Primitive Variables.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Bitwise Operators Fall 2008 Dr. David A. Gaitros
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
SEC (1.4) Representing Information as bit patterns.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Primitive Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Programming Principles Operators and Expressions.
Georgia Institute of Technology Introduction to Java, and DrJava part 1 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
Binary 1 Basic conversions.
BASIC ELEMENTS OF A COMPUTER PROGRAM
CSCI 198: Lecture 4: Data Representation
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
CSCI 161: Lecture 4: Data Representation
Multiple variables can be created in one declaration
Representing Information as bit patterns
Java Programming: From Problem Analysis to Program Design, 4e
IDENTIFIERS CSC 111.
Building Java Programs Chapter 2
Introduction to Programming
Chapter 2: Basic Elements of Java
Introduction to Java, and DrJava part 1
Building Java Programs
Introduction to Java, and DrJava
Introduction to Java, and DrJava
Introduction to Java, and DrJava part 1
ASCII LP1.
Presentation transcript:

Agenda ASCII char N int Character class char N String Bitwise operators homework

ASCII codes ASCII is an acronym for American Standard Cod for Information Interchange All characters type are stored as numbers. Characters like 0…9, all upper/lower case letters, special symbols like,{,}, _, -, ?, : ; ) Refer to BPJ Appendix D for more information CharacterASCIICharacterASCII A65Y89 B66Z90

Why do we need ASCII code? Earlier we had EBSIDIC(Extended Binary Code Decimal Interchange Code) codes that was capable of accommodating English Letters, Punctuations and Digits. Then came the need of accommodating European alphabets and mathematical signs, box drawing characters... so ASCII was formed which could accommodate 256 codes. Now Unicode is introduced so that we can accommodate the alphabets of all the languages in the world and additional signs and symbols

What is Unicode? Programs are written using the Unicode character set. The Java programming language represents text in sequences of 16-bit code units, using the UTF-16 encoding. Except for comments, identifiers, and the contents of character and string literals, all input elements in a program are formed only from ASCII characters

How to convert a character to ascii? char aChar = ‘A’; int asciiCode = (int)aChar; How to convert an ascii to a character? int aNum = 65; char aChar= (char)aNum;

illegal statements Charater type char and String types can’t be stored into each other. char ch = “A”; String Str = ‘A’; or String str = “B”; char ch=str;

Surprising legal statements int and char can be added and store into int variable int x = 10; char y = ‘a’; int z = x + y; What z will be?

Is this legal? int aInt = 10; char aChar = ‘a’; aInt = aChar; => ok? aInt = ‘a’; => ok? aInt = 10 + aChar; => ok? int aInt = 10; char aChar = aInt;=> ok? aChar=(int)aInt; char aChar = 10;=> ok?

You can do this Look at ASCII chart, guess what will be the output for the following statement. char aChar = ‘A’; //65 int num = aChar + 10; //75 char bChar = (char)num; what is bChar?

Character class Provides many methods isAlphabetic() isDigit() isLowerCase() isUpperCase()return type?? isWhiteSpace() toUpperCase() toLowerCase() How to call the method?

char N String char aChar = ‘A’ ; String aStr = “B” ; aChar = aStr; => ok? aStr = aChar; => ok? aStr = aChar + “ “ ; => ok Conversion from char to string. Conversion from string to char aChar = aStr.CharAt(0); aChar = aStr.CharAt(1); => ok?

Bitwise operators Applied to binary only Boolean operators- && || Bitwise operators- & | Bitwise AND - &

Bitwise OR : | Bitwise exclusive OR: (XOR) ^ Short circuit evaluation: the left operand is evaluated first. If the result of the entire expression can be determined by the value of the left operand, then no other operands will be evaluated

Bitwise NOT- ~ 0 => 11 => 0 AND (90 10 & ) OR (90 10 | )

XOR ^ (90 10 ^ ) NOT ~ most significant bit(msb) 0 – positive 1 - negative

Bitwise operations Decimal shifting to the right > 28.3 dividing by 10 Decimal shifting to the left > 2830 multiplying by 10 Binary shifting to the right: >> 32 >> 3 shift the bits(representing number 7) to the right 3 times 2*2*2=8 32/8 = 4 Binary shifting to the left: << 7 << 2 shift the bits to the left 2 times

A bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, primitive action directly supported by the processor, and is used to manipulate values for comparisons and calculations. On simple low-cost processors, typically, bitwise operations are substantially faster than division, several times faster than multiplication, and sometimes significantly faster than additionbit patternsbinary numeralsbits processor

Homework Preview BPJ 31, not 27 as specified in lesson plan; Barron’s p Do all the exercises on BPJ 13 Convert a String to an array of characters. 1.Hard code the text to a variable : “ Programs are written using the Unicode character set. The Java programming language represents text in sequences of 16-bit code units, using the UTF-16 encoding. ” 2.Declared an char array with the size of the text. 3.Using a for loop and charAt(..) to store each symbol(letter, space, period..) into the char array 4.Use enhanced for loop to print out the char array