FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a.

Slides:



Advertisements
Similar presentations
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Advertisements

© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Fundamentals of Strings and Characters Characters.
Introduction to Computers and Programming Lecture 7:
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9: Characters * Character primitives * Character Wrapper class.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Data Representation in Computers
Data Representation (in computer system) Computer Fundamental CIM2460 Bavy LI.
1 Agenda Variables (Review) Example Input / Output Arithmetic Operations Casting Char as a Number (if time allow)
Computer Arithmetic: Binary, Octal and Hexadecimal Presented by Frank H. Osborne, Ph. D. © 2005 ID 2950 Technology and the Young Child.
Homework Reading –Finish K&R Chapter 1 (if not done yet) –Start K&R Chapter 2 for next time. Programming Assignments –DON’T USE and string library functions,
L EC. 02: D ATA T YPES AND O PERATORS (1/2) Fall Java Programming.
© by Kenneth H. Rosen, Discrete Mathematics & its Applications, Sixth Edition, Mc Graw-Hill, 2007 Chapter 3 (Part 3): The Fundamentals: Algorithms, the.
MATH 224 – Discrete Mathematics
The character data type char
Computer System Basics 1 Number Systems & Text Representation Computer Forensics BACS 371.
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
Computer Structure & Architecture 7c - Data Representation.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 2 Number.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single quotes, for.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
Introduction to Computer Design CMPT 150 Section: D Ch. 1 Digital Computers and Information CMPT 150, Chapter 1, Tariq Nuruddin, Fall 06, SFU 1.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
Elements of Coding and Encryption Continuation 1.
Computer System Basics 1 Number Systems & Text Representation Computer Forensics BACS 371.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
CISC1100: Binary Numbers Fall 2014, Dr. Zhang 1. Numeral System 2  A way for expressing numbers, using symbols in a consistent manner.  " 11 " can be.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs -
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
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.
Number Systems Denary Base 10 Binary Base 2 Hexadecimal Base 16
COMP Primitive and Class Types Yi Hong May 14, 2015.
Programming Fundamentals. Overview of Previous Lecture Phases of C++ Environment Program statement Vs Preprocessor directive Whitespaces Comments.
Characters and Strings
Ch04-Number Theory and Cryptography 1. Introduction to Number Theory Number theory is about integers and their properties. We will start with the basic.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Constants, Data Types and Variables
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
1.4 Representation of data in computer systems Character.
Primitive Types Four integer types: Two floating-point types:
Topic: Binary Encoding – Part 2
Binary Representation in Text
Binary Representation in Text
Topic: Binary Encoding – Part 1
Unit 2.6 Data Representation Lesson 2 ‒ Characters
The Machine Model Memory
ECE Application Programming
Data Transfer ASCII FILES.
EPSII 59:006 Spring 2004.
Variables and Primative Types
Data Encoding Characters.
Coding Schemes and Number Systems
Primitive and Reference Data Values
INPUT & OUTPUT scanf & printf.
Chapter 8 Characters In Java single characters are represented using the data type char. Character constants are written as symbols enclosed in single.
Fundamentals of Data Representation
Presenting information as bit patterns
COMS 161 Introduction to Computing
COMS 161 Introduction to Computing
Number Theory.
functions: argument, return value
Comp Org & Assembly Lang
Learning Intention I will learn how computers store text.
Names of variables, functions, classes
Programming Fundamental-1
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Presentation transcript:

FATİH SULTAN MEHMET VAKIF UNIVERSITY Faculty of Engineering & Architecture Computer Engineering Department MAT217E - DİSCRETE STRUCTURES Slides for a Course Based on the Text Discrete Mathematics & Its Applications (7th Edition) by Kenneth H. Rosen 07.12.2014 MAT217E Discrete Structures Lecture 8

RECALL: Characters as Integers in Java It is legal to assign a char to an int variable int i = ‘a’; // assigns 97 to i It is legal to assign an int to an char variable char c = 97; // assigns ‘a’ to c It is possible to perform arithmetic on char variables char ch = ‘a’; ch = ch + 1; // assigns ‘b’ to ch

The char Data Type in Java The Java char data type provides access to single characters. char literals are enclosed in single quote marks. ‘a’, ‘Z’, ‘\n’, ‘1’ Don’t confuse char literals with String literals. char literals are enclosed in single quotes. (tek tırnakla tanımlanır.) String literals are enclosed in double quotes. (çitf tırnakla tanımlanır.) Example: " Fatih Sultan Mehmet Vakif University"

Intro to OOP with Java, C. Thomas Wu ASCII Encoding For example, character 'O' is 79 (row value 70 + col value 9 = 79). O 9 70 Characters can be stored in a computer memory using the ASCII encoding. The ASCII codes range from 0 to 127. The character 'A' is represented as 65, for example. The ASCII values from 0 to 32 are called nonprintable control characters. For example, ASCII code 04 eot stands for End of Transmission. We can use this character to signal the end of transmission of data when sending data over a communication line. ©The McGraw-Hill Companies, Inc.

Unicode Internally, characters are stored as numbers. Character data in Java is stored as Unicode characters. The Unicode character set can consist of 65536 (216) individual characters. This means that each character takes up 2 bytes in memory. The first 256 characters in the Unicode character set are compatible with the ASCII* character set. *American Standard Code for Information Interchange

Unicode A B 00 65 00 66 1 1

stored in memory as binary numbers. Unicode Characters are stored in memory as binary numbers. A B 00 65 00 66 1 1

Unicode A B 00 65 00 66 The binary numbers represent these decimal values. B 00 65 00 66 1 1

Unicode A B 00 65 00 66 The decimal values represent these characters. 1 1

Exercise: Character Arithmetic Implement a method toHexDigit that takes an integer and returns the corresponding hexadecimal digit as a character. Thus, if the argument is between 0 and 9, the method should return the corresponding character between '0' and '9'. If the argument is between 10 and 15, the method should return the appropriate letter in the range 'A' through 'F'. If the argument is outside this range, the method should return '?'. public char toHexDigit(int n) { if (n >= 0 && n <= 9) { return (char) ('0' + n); } else if (n >= 10 && n <= 15) { return (char) ('A' + n - 10); } else { return '?'; }

Simple Encryption Variations on the following have been used to encrypt messages for thousands of years. Convert a message to capitals. Think of each letter as a number between 1 and 26. Apply an invertible modular function to each number. Convert back to letters (0 becomes 26).

Letter  Number Conversion Table D E F G H I J K L M 1 2 3 4 5 6 7 8 9 10 11 12 13 N O P Q R S T U V W X Y Z 14 15 16 17 18 19 20 21 22 23 24 25 26

Encryption example Let the encryption function be f (a) = (3a + 9) mod 26 Encrypt “Stop Thief” STOP THIEF (capitals) 19,20,15,16 20,8,9,5,6 14,17,2,5 17,7,10,24,1 NQBE QGJXA

g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26 Decryption example Decryption works the same, except that you apply the inverse function. EG: Find the inverse of f (a) = (3a + 9) mod 26 If we didn’t have to deal with mod 26, inverse would be g (a) = 3-1 (a - 9) We’ll see that since gcd(3,26) = 1, the inverse of 3 is actually well defined modulo 26 and is the number 9. This gives: g (a) = 9 (a - 9) mod 26 = (9a – 3) mod 26 L9

Caesar’s Cipher f (a) = (a+3) mod 26

Exercise: Write a program to find the given number is Armstrong number or not. Armstrong numbers are the sum of their own digits to the power of the number of digits. It is also known as narcissistic numbers. Example: 153 = 𝟏 𝟑 + 𝟓 𝟑 + 𝟑 𝟑