Upload
kirima
View
33
Download
0
Embed Size (px)
DESCRIPTION
DATA TYPES. Numeric Data Types. integer floating point numbers fixed point real numbers boolean character. Numeric Data Types. integer operations: arithmetic, relational, and bit operations, assignment. s magnitude. - PowerPoint PPT Presentation
Citation preview
DATA TYPES
Numeric Data Types
• integer
• floating point numbers
• fixed point real numbers
• boolean
• character
Numeric Data Types
• integer
operations: arithmetic, relational, and bit operations, assignment
s magnitude
1 bit 15 bits
Numeric Data Types
• floating point real numbers
representation limitations (precision)
S exponent mantissa
1 bit 8 bits 23 bits
Numeric Data Types
• fixed point real numbers
precise representation within a restricted range
stored much like character strings using BCD(1 or 2 digits / byte)
hardware supported or software simulated
Numeric Data Types
• booleans
may address a single bit or an entire storage unit (byte, word)
C++: bool (true, false)Pascal: boolean (true, false)C: no boolean type (0=false)
Numeric Data Types
• character
most use ASCII representation which uses values 0-127 to encode each of 128 characters
Java uses 16 bit Unicode for international alphabets
represented by underlying hardware character set and support relational operations
ASCII Character Table
0 1 2 3 4 5 6 7 8 9 A B C D E F
0 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI
1 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
2 SP ! " # $ % & ' ( ) * + , - . / 3 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
4 @ A B C D E F G H I J K L M N O
5 P Q R S T U V W X Y Z [ \ ] ^ _
6 ` a b c d e f g h i j k l m n o
7 p q r s t u v w x y z { | } ~ DEL
Character String Types
Design Issues:
• static or dynamic length?
• primitive type or character array with special properties?
• operators or library functions?
Character String Types
Length options:
• static - length is fixed at compile time to the declared length
• limited length dynamic - maximum length is specified in the static declaration of the string variable
• dynamic length with no maximum
Character String Types
Length options:
• static -FORTRAN 77, Pascal
• limited length dynamic - C/C++ using arrays of characters
• dynamic length with no maximum -SNOBOL4, Perl, C++ string class, Java
Character String Types
String operations:
• assignment, comparison, concatenation, substring extraction
• implemented with operator symbols or library functions
Character String Types
String operations:
C character arrays: C++ string class:
assignment strcpy(s1,s2) =comparison strcmp(s1,s2) ==, !=, <, >, >=, <=concatenation strcat (s1,s2) +substring strstr(s1,s2) substr(start, len)
Character String Types
Implementation of string types:
• software used for storage, retrieval and manipulation or directly supported in hardware
• compile time or run time descriptors
Descriptors
A descriptor stores the necessary attributes of a variable. It is used for type checking, and memory allocation and deallocation.
Static descriptors are are built by the compiler, as a part of the symbol table and are not required after compilation
For dynamic attributes the descriptor is maintained during execution.
Character String Types
Compile time descriptor:
Type (static string)
Length
Address
Character String Types
Run time descriptor:
Type (limited dynamic string)
Maximum Length
Current Length
Address
Character String Types
Run time descriptor:
Type (dynamic string)
Current Length
Address