18
DATA TYPES

DATA TYPES

  • 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

Page 1: DATA TYPES

DATA TYPES

Page 2: DATA TYPES

Numeric Data Types

• integer

• floating point numbers

• fixed point real numbers

• boolean

• character

Page 3: DATA TYPES

Numeric Data Types

• integer

operations: arithmetic, relational, and bit operations, assignment

s magnitude

1 bit 15 bits

Page 4: DATA TYPES

Numeric Data Types

• floating point real numbers

representation limitations (precision)

S exponent mantissa

1 bit 8 bits 23 bits

Page 5: DATA TYPES

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

Page 6: DATA TYPES

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)

Page 7: DATA TYPES

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

Page 8: DATA TYPES

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

Page 9: DATA TYPES

Character String Types

Design Issues:

• static or dynamic length?

• primitive type or character array with special properties?

• operators or library functions?

Page 10: DATA TYPES

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

Page 11: DATA TYPES

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

Page 12: DATA TYPES

Character String Types

String operations:

• assignment, comparison, concatenation, substring extraction

• implemented with operator symbols or library functions

Page 13: DATA TYPES

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)

Page 14: DATA TYPES

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

Page 15: DATA TYPES

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.

Page 16: DATA TYPES

Character String Types

Compile time descriptor:

Type (static string)

Length

Address

Page 17: DATA TYPES

Character String Types

Run time descriptor:

Type (limited dynamic string)

Maximum Length

Current Length

Address

Page 18: DATA TYPES

Character String Types

Run time descriptor:

Type (dynamic string)

Current Length

Address