Byte

From Free Pascal wiki
Revision as of 15:57, 26 July 2006 by Onr (talk | contribs)
Jump to navigationJump to search

Italiano (it) English (en)

A byte is an unsigned integer in the range of 0 .. 255. A byte and a char are the same thing, except a byte can only be referred to as a numeric type, while a char can be used as a character, or as part of a string type, and cannot be used in an arithmetic expression.

For example:

Var c: byte;
ch: char;
begin
     c := 64; ch := 'A'; { are the same action, and are legal }
     c := 'A'; ch := 64; { while they are the same action, this is illegal }
end.

The use of byte or char as a data type provides better documentation as to the purpose of the use of the particular variable. The byte type can be coerced to char by using the chr function. Char type values can be coerced to byte by using the ord function

The above program corrected to legal use:

Var c: byte;
ch: char;
begin
     c := 64; ch := 'A'; { are the same action, and are legal }
     c := ord('A'); ch := Chr(64); { now legal }
end.


navigation bar: data types
simple data types

boolean byte cardinal char currency double dword extended int8 int16 int32 int64 integer longint real shortint single smallint pointer qword word

complex data types

array class object record set string shortstring