The three functions presented here format numbers into a character string in different contexts.
Bin$ ( Number AS Long [ , Digits AS Integer ] ) AS String
Bin$ (..) formats a data type Long into its binary representation. If Digits=d is optional, the representation is filled with leading zeros so that exactly d digits are output. The default is d=8.
Examples:
PRINT Bin$(77) 1001101 PRINT Bin(77, 16) 0000000001001101
Hex$ ( Number AS Long [ , Digits AS Integer ] ) AS String
Hex$ (..) formats a number of the data type Long into its hexadecimal representation. If Digits=d is optional, the representation is filled with leading zeros so that exactly d digits are output.
Examples:
PRINT Hex$(2014) 7DE PRINT Hex(2014, 8) 000007DE
A sign for a number of the data type Short or Integer automatically expands the data type to Long. If the hexadecimal representation is limited to 16 bits, the AND operator must also be used or alternatively Hex (CLong (number, 4).
Examples:
DIM bX AS Byte ' 8 Bit unsigned DIM sX AS Short ' 16 Bit with (negative) sign bX = 200 sX = -456 PRINT Hex$(bX), Hex$(sX), Hex$(CLong(sX) AND &H00FFFF), Hex$(CLong(sX), 4) C8 FFFFFFFFFFFFFE38 FE38 FE38
Format ( Expression [ , Format ] ) AS String
Format(..) converts the expression into a string. You can optionally specify the format with a format string that depends on the type of expression. The format function can format a date, times, numbers and currencies. Without a special format string, the constant gb. standard is used.
These format definitions are possible:
Under the link: http://gambaswiki.org/wiki/cat/constant you can currently find a list of predefined constants and in → chapter 9.2 notes and examples on user-defined formats.
Die drei vorgestellten Funktionen formatieren Zahlen in unterschiedlichen Kontexten in eine Zeichenkette.
Bin$ ( Number AS Long [ , Digits AS Integer ] ) AS String
Bin$(..) formatiert eine vom Datentyp Long in ihre binäre Darstellung. Wenn Digits=d optional angegeben ist, wird die Darstellung mit führenden Nullen aufgefüllt, so dass genau d Ziffern ausgegeben werden. Der Standard ist d=8.
Beispiele:
PRINT Bin$(77) 1001101 PRINT Bin(77, 16) 0000000001001101
Hex$ ( Number AS Long [ , Digits AS Integer ] ) AS String
Hex$(..) formatiert eine Zahl vom Daten-Typ Long in ihre hexa-dezimale Darstellung. Wenn Digits=d optional angegeben ist, wird die Darstellung mit führenden Nullen aufgefüllt, so dass genau d Ziffern ausgegeben werden.
Beispiele:
PRINT Hex$(2014) 7DE PRINT Hex(2014, 8) 000007DE
Ein Vorzeichen für eine Zahl vom Daten-Typ Short oder Integer erweitert den Daten-Typ automatisch auf Long. Wenn die hexadezimale Darstellung auf 16 Bit beschränkt wird, dann muss zusätzlich der AND-Operator verwendet werden oder alternativ Hex(CLong(number, 4).
Beispiele:
DIM bX AS Byte ' 8 Bit vorzeichenlos DIM sX AS Short ' 16 Bit mit (negativem) Vorzeichen bX = 200 sX = -456 PRINT Hex$(bX), Hex$(sX), Hex$(CLong(sX) AND &H00FFFF), Hex$(CLong(sX), 4) C8 FFFFFFFFFFFFFE38 FE38 FE38
Format ( Expression [ , Format ] ) AS String
Format(..) konvertiert den Ausdruck in einen String. Das Format können Sie optional mit einem Format-String festlegen, der von der Art des Ausdrucks abhängt. Die Format-Funktion kann ein Datum, Zeiten, Zahlen und Währungen formatieren. Ohne einen speziellen Format-String wird die Konstante gb.Standard genutzt.
Diese Format-Festlegungen sind möglich:
Unter dem Link: http://gambaswiki.org/wiki/cat/constant finden Sie gegenwärtig eine Liste der vordefinierten Konstanten und im → Kapitel 9.2 Hinweise und Beispiele zu den benutzer-definierten Formaten.