DATA TYPES Numeric Data Types integer floating point


















- Slides: 18

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 1 bit magnitude 15 bits

Numeric Data Types • floating point real numbers representation limitations (precision) S 1 bit exponent 8 bits mantissa 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++: Pascal: C: bool (true, false) boolean (true, false) 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 EOT ENQ ACK BEL BS HT LF VT FF CR SO SI 1 DLE DC 1 DC 2 DC 3 DC 4 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 SNOBOL 4, 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: assignment comparison concatenation substring strcpy(s 1, s 2) strcmp(s 1, s 2) strcat (s 1, s 2) strstr(s 1, s 2) C++ string class: = ==, !=, <, >, >=, <= + 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 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