The key difference is, 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.
byte will always be the same size as an
ansiChar, but in the future
char may be considered a synonym for
program byteDemo(input, output, stderr); var foo: byte; bar: char; begin // those two assignments are physically the same foo := 65; bar := 'A'; // although they are the same action, // the following would be illegal //foo := 'A'; //bar := 65; end.
The use of
byte as a data type provides better documentation as to the purpose of the use of the particular variable.
Conversion to and from character
The above program corrected to legal use:
program ordChrDemo(input, output, stderr); var foo: byte; bar: char; begin foo := 65; bar := 'A'; foo := ord('A'); // chr(65) is equivalent to #65 bar := chr(65); bar := #65; // alternatively: typecasts // typecasts of constant expressions // are guaranteed to happen at compile-time foo := byte('A'); bar := char(65); end.
program binStrDemo(input, output, stderr); var foo: byte; begin foo := 10; writeLn(binStr(foo, 8)); end.
The output is:
A more versatile function is
intToBin provided by the
|simple data types|
|complex data types|