SlideServe
Menu
Préférences
© SlideServe · v2026

Programming Language Concepts (CIS 635)

rose-stokes avatar
27 diapositives · 418 Views · Nov 13, 2014

This comprehensive overview explores elementary data types in programming languages, focusing on their specifications, implementation, and operations. It covers standard types such as integers, floats, characters, and booleans, including their binary representations and arithmetic operations. The text elaborates on the IEEE floating-point standard, detailing its structure and the significance of components like the sign, exponent, and mantissa. The discussion also highlights subranges, enumeration types, and their applications, offering insights into their use in programming practice.

Programming Language Concepts (CIS 635) - slide 1
01 / 27Programming Language Concepts (CIS 635)
1 / 17

Télécharger la présentation

Programming Language Concepts (CIS 635)
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT, www.cs.njit.edu/~elsa/635

  2. Elementary Data Types • Data objects contain single data value with no components • Standard elementary types include: integers, reals, characters, booleans, enumerations, pointers (references in SML)

  3. Specification of Elementary Data Types • Basic attributes of type usually used by compiler and then discarded • Some partial type information may occur in data object • Values usually match with hardware types: 8 bits, 16 bits, 32 bits, 64 bits • Operations: primitive operations with hardware support, and user-defined operations built from primitive ones

  4. Integers – Specification • Range of integers for some fixed minint to some fixed maxint, typically -2^31 through 2^31 – 1 or –2^30 through 2^30 - 1 • Standard collection of operators: +, -, *, /, mod, ~ (negation) • Standard relational operations: =, <, >, <=, >=, =/=

  5. S Data Binary integer Sign bit (0 for +, 1 for -) Integers - Implementation • Implementation: • Binary representation in 2’s complement arithmetic • Three different standard representations:

  6. S Data Integers - Implementation • First kind: Binary integer Sign bit (0 for +, 1 for -)

  7. T Address S Data T S Data Integers – Implementation • Secondkind • Third kind Type descriptor Sign bit Type descriptor Sign bit

  8. 0 1 0 0 1 1 0 0 Integer Numeric Data • Positive values 64 + 8 + 4 = 76 sign bit

  9. 1 1 1 1 1 1 1 1 Integer Arithmetic – Theory • Based on idea that given n bits, use 2n = 0 mod 2n • 2n – 1 = 2n-1 + . . . + 2 + 1 = - 1 mod 2n • - 1 

  10. 1 0 1 1 0 0 1 1 1 0 1 1 0 1 0 0 0 1 0 0 1 1 0 0 2’s Complement Arithmetic • Initial value: = 76 • One’s Complement: = - 77 • Two’s Complement: = - 76

  11. Subranges • Example (Ada): A:integer range 10..20 • Subtype of integers (implicit coercion into integer)

  12. Subranges • Data may require fewer bits than integer type • Data in example above require only 4 bits • Range checking usually requires some runtime time information and dynamic type checking

  13. S E M IEEE Floating Point Format • IEEE standard 754 specifies both a 32- and 64-bit standard • At least one supported by most hardware • Numbers consist of three fields: • S (sign), E (exponent), M (mantissa)

  14. Floating Point Numbers: Theory • Every non-zero number may be uniquely written as (-1)S * 2 e* m where 1  m < 2 and S is either 0 or 1

  15. Floating Point Numbers: Theory • Every non-zero number may be uniquely written as (-1)S * 2 (E – bias) * (1 + (M/2N)) where 0  M < 1 • N is number of bits for M (23 or 52) • Bias is 127 of 32-bit ints, 1023 for 64-bit

  16. IEEE Floating Point Format (32 Bits) • S: a one-bit sign field. 0 is positive. • E: an exponent in excess-127 notation. Values (8 bits) range from 0 to 255, corresponding to exponents of 2 that range from -127 to 128.

  17. IEEE Floating Point Format (32 Bits) • M: a mantissa of 23 bits. Since the first bit of the mantissa in a normalized number is always 1, it can be omitted and inserted automatically by the hardware, yielding an extra 24th bit of precision.

  18. Exponent Bias • If 8 bits (256 values) +127 added to exponent to get E • If E = 127 then 127-127 = 0 is true exponent • If E = 129 then 129-127 = 2 is true exponent • If E = 120 then 120-127 = -7 is true exponent

  19. Floating Point Number Range • In 32-bit format, the exponent has 8 bits giving a range from –127 to 128 for exponent • This give a number range from 10-38 to 1038 roughly speaking

  20. Floating Point Number Range • In 64-bit format,the exponent is extended to 11 bits giving a range from -1023 to +1024 for the exponent • This gives a range from 10-308 to 10308 roughly speaking

  21. Decoding IEEE format • Given E, and M, the value of the representation is: Parameters Value • E=255 and M  0 An invalid number • E=255 and M = 0  • 0<E<255 2{E-127}(1+(M/ 223)) • E=0 and M  0 2 -126 (M / 223) • E=0 and M=0 0

  22. Example Floating Point Numbers • +1= 20*1= 2{127-127}*(1 + .0) 0 01111111 000000… • +1.5= 20*1.5= 2{127-127}*(1+ 222/ 223) 0 01111111 100000… • -5= -22*1.25= 2{129-127}*(1+ 221/ 223) 1 10000001 010000…

  23. Other Numeric Data • Short integers (C) - 16 bit, 8 bit • Long integers (C) - 64 bit • Boolean or logical - 1 bit with value true or false (often stored as bytes) • Byte - 8 bits

  24. Other Numeric Data • Character - Single 8-bit byte - 256 characters • ASCII is a 7 bit 128 character code • Unicode is a 16-bit character code (Java) • In C, a char variable is simply 8-bit integer numeric data

  25. Enumerations • Motivation: Type for case analysis over a small number of symbolic values • Example: (Ada) Type DAYS is {Mon, Tues, Wed, Thu, Fri, Sat, Sun} • Implementation: Mon  0; … Sun  6 • Treated as ordered type (Mon < Wed) • In C, always implicitly coerced to integers