Data Type Summary - E

advertisement
Data Type Summary
Data types and their definitions vary from language to language. For example, in Java a byte is
8 bits with a range of -128 to 127 while in C# a byte is 8 bits but has a range of 0 to 255. In the
section “Data types for selected languages”, you can see the variation between languages. For
the purpose of creating pseudocode, we will use the following designations:
Type
byte
char
short or
shortInteger
integer
long or
longInteger
float
double
boolean
string
Range
-128 to 127
U+0000 to U+ffff
-32,768 to 32,767
Size, Precision
8 bits
16 bits
16 bits
-2,147,483,648 to 2,147,483,647
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
32 bits
64 bits
-3.4E+38 to 3.4E+38
-1.79E+308 to 1.79E+308
true or false
A group of characters
32 bits, 7 digits
64 bits, 15-16 digits
Two bytes
Varies
Every piece of data, called fields, you use in a program must be declared. A declaration consists
of a type, identifier, and optionally, an assignment which places an initial value in the field. In
general, fields are broken down into variables and constants. Variables are fields who’s value
will change during the course of a program, while constants are fields who’s values do not
change during program execution.
Syntax for declaring fields vary slightly between variables and constants. As a matter of
convention, Hungarian or camel casing is used for variables. For this notation, words in the
identifier are all capitalized with the exception of the first word, and all other letters are lower
case. There are no embedded spaces. Only letters, numerals, and the underscore can be used
in an identifier. The first letter must be a letter. Constants, on the other hand are declared
using all upper case letters, separating each word with the underscore character. You may also
precede the type with the word “constant”. Constants must always have a value assigned to it
at the time it is declared.
Examples:
Variables
string companyName
integer age
Boolean isValid = true
Constants:
double PI = 3.142857
constant integer INCHES_IN_A_FOOT = 12
char A_LETTER = ‘a’
Note that variables may also have a value assigned at the time of declaration, but constants
must have a value assigned.
Data types of selected languages
C# Primitive Data Types
Integral Data Types
Type
sbyte
Range
-128 to 127
Size
Signed 8-bit integer
byte
0 to 255
Unsigned 8-bit integer
char
U+0000 to U+ffff
Unicode 16-bit character
short
-32,768 to 32,767
Signed 16-bit integer
ushort
0 to 65,535
Unsigned 16-bit integer
int
-2,147,483,648 to 2,147,483,647
Signed 32-bit integer
uint
0 to 4,294,967,295
Unsigned 32-bit integer
long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Signed 64-bit integer
ulong
0 to 18,446,744,073,709,551,615
Unsigned 64-bit integer
Floating-Point Data Types
Type
float
Approximate range
-3.4E+38 to 3.4E+38
Precision
7 digits
Size
Signed 32-bit
double
-1.79E+308 to 1.79E+308
15-16 digits
Signed 64-bit
Precision
28-29 significant digits
Size
Signed-64 bit
Decimal Data Type
Type
decimal
Approximate Range
-7.9E+28 to 7.9E+28
Boolean Data Type
Type
bool
Value
true or false
Java Primitive Data Types
Integral Data Types
Type
byte
Range
-128 to 127
Size
Signed 8-bit integer
short
-32,768 to 32,767
Signed 16-bit integer
int
-2,147,483,648 to 2,147,483,647
Signed 32-bit integer
long
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Signed 64-bit integer
Char Data Types
Type
char
Range
U+0000 to U+ffff
Size
Unicode 16-bit character
Floating-Point Data Types
Type
float
Approximate range
-3.4*1038 to +3.4*1038
Precision
6-7 digits
Size
Signed 32-bit
double
-1.70*10308 to +1.7*10308
15-16 digits
Signed 64-bit
Boolean Data Type
Type
boolean
Value
true or false
Visual Basic Primitive Data Types
Integral Data Types
Type
byte
Range
0 to 255
Size
Unsigned 8-bit integer
SByte
char
-128 through 127
0 to 65,535
Signed 8-bit integer
Unsigned 16-bit integer
Short
UShort
Integer
UInteger
Long
-32,768 through 32,767 (signed)
0 through 65,535 (unsigned)
-2,147,483,648 through 2,147,483,647 (signed)
0 through 4,294,967,295 (unsigned)
-9,223,372,036,854,775,808 through 9,223,372,036,854,775,807
(9.2...E+18 †)
0 through 18,446,744,073,709,551,615 (1.8...E+19 †) (unsigned)
Signed 16-bit integer
Unsigned 16-bit integer
Signed 32-bit integer
Unsigned 32-bit integer
Signed 64-bit integer
ULong
Unsigned 64-bit integer
Floating-Point Data Types
Type
single
double
decimal
Approximate range
-3.4028235E+38 through -1.401298E-45 † for
negative values;
1.401298E-45 through 3.4028235E+38 † for
positive values
-1.79769313486231570E+308 through 4.94065645841246544E-324 † for negative values;
4.94065645841246544E-324 through
1.79769313486231570E+308 † for positive values
0 through +/79,228,162,514,264,337,593,543,950,335 (+/7.9...E+28) † with no decimal point; 0 through +/7.9228162514264337593543950335 with 28 places
to the right of the decimal;
smallest nonzero number is +/0.0000000000000000000000000001 (+/-1E-28) †
Precision
varies
Size
Signed 32-bit
varies
Signed 64-bit
29 digits
Signed 128-bit
† In scientific notation, "E" refers to a power of 10. So 3.56E+2 signifies 3.56 x 102 or 356, and 3.56E-2 signifies
3.56 / 102 or 0.0356.
Boolean Data Type
Type
boolean
Value
true or false
Date Data Type
Type
date
Value Range
0:00:00 (midnight) on January 1, 0001 through
11:59:59 PM on December 31, 9999
Size
8 bytes
C++ Primitive Data Types
Integral Data Types
Type
char
short int
int
long int
long long int
Value Range *
signed: -128 to 127
unsigned: 0 to 255
signed: -32768 to 32767
unsigned: 0 to 65535
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
signed: –9223372036854775808
to 9223372036854775807
unsigned: 0 to 18446744073709551615
Size *
1 byte
2 bytes
4 bytes
4 bytes
8 bytes
Floating Point Data Types
Type
float
double
long double
Value Range *
+/- 3.4e +/- 38 (~7 digits)
+/- 1.7e +/- 308 (~15 digits)
+/- 1.7e +/- 308 (~15 digits)
Size *
4 bytes
8 bytes
8 bytes
Boolean & Other Data Types
Type
bool
wchar_t
Value Range *
true or false
1 wide character
Size *
1 byte
2 or 4 bytes
* The values of the columns Size and Range depend on the system the program is compiled for. The values shown
above are those found on most 32-bit systems. But for other systems, the general specification is that int has the
natural size suggested by the system architecture (one "word") and the four integer types char, short, int and long
must each one be at least as large as the one preceding it, with char being always one byte in size. The same
applies to the floating point types float, double and long double, where each one must provide at least as much
precision as the preceding one.
Download