Byte/de

From Free Pascal wiki
Revision as of 14:30, 27 July 2007 by Swen (talk | contribs) (New page: {{Byte}} Ein '''byte''' ist ein vorzeichenloser integer im Bereich von 0 .. 255. Ein Byte hat eine Länge von 8 Bit. A byte and a char are the same thing, except a...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) italiano (it) русский (ru) 中文(中国大陆)‎ (zh_CN)

Ein byte ist ein vorzeichenloser integer im Bereich von 0 .. 255. Ein Byte hat eine Länge von 8 Bit. 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.

Zum Beispiel: <delphi>

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

</delphi>

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:

<delphi>

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

</delphi>


Navigationsleiste zum Thema: Datentypen
einfache Datentypen

boolean (Boolescher Wert) byte cardinal (Kardinalzahl) char currency (Währung) double dword extended int8 int16 int32 int64 integer longint real (reelle Zahl) shortint single smallint pointer qword word

strukturierte Datentypen

array (Feld) class (Klasse) object (Objekt) record (Datensatz) set (Menge) string (Zeichenkette) shortstring (kurze Zeichenkette)