User Tools

Site Tools


k9:k9.1:start

9.1 Formatting functions

The three functions presented here format numbers into a character string in different contexts.

9.1.1 Function Bin$ or Bin

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

9.1.2 Function Hex$ or Hex

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

9.1.3 Function Format$ or Format

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:

  • A predefined format as integer constant.
  • A user-defined format as a string describing the format.

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.

The website uses a temporary session cookie. This technically necessary cookie is deleted when the browser is closed. You can find information on cookies in our privacy policy.
k9/k9.1/start.txt · Last modified: 11.02.2022 (external edit)

Page Tools