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.