Wiki source for KeyPgHex


Show raw source

{{fbdoc item="title" value="HEX"}}----
Returns the hexadecimal of the given number

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUbyte|ubyte]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUshort|ushort]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUlong|ulong]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUlongint|ulongint]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgConst|const]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]] ) [[KeyPgAs|as]] [[KeyPgString|string]]

[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUbyte|ubyte]], [[KeyPgByval|byval]] //digits// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUshort|ushort]], [[KeyPgByval|byval]] //digits// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUlong|ulong]], [[KeyPgByval|byval]] //digits// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgUlongint|ulongint]], [[KeyPgByval|byval]] //digits// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **Hex** ( [[KeyPgByval|byval]] //number// [[KeyPgAs|as]] [[KeyPgConst|const]] [[KeyPgAny|any]] [[KeyPgPtr|ptr]], [[KeyPgByval|byval]] //digits// [[KeyPgAs|as]] [[KeyPgLong|long]] ) [[KeyPgAs|as]] [[KeyPgString|string]]
##
{{fbdoc item="usage"}}##
//result// = **Hex**[$]( //number// [, //digits// ] )
##
{{fbdoc item="param"}}
##//number//##
A number or expression evaluating to a number. A floating-point number will be converted to a ##[[KeyPgLongint|longint]]##.
##//digits//##
Optional number of digits to return.

{{fbdoc item="ret"}}
A [[KeyPgString|string]] containing the unsigned hexadecimal representation of ##//number//##.

{{fbdoc item="desc"}}
Returns the unsigned hexadecimal string representation of the integer ##//number//##. Hexadecimal digits range from 0-9, or A-F.

If you specify ##//digits//## > 0, the result string will be exactly that length. It will be truncated or padded with zeros on the left, if necessary.

The length of the string will not go longer than the maximum number of digits required for the type of ##//number//## (8 for a ##[[KeyPgLong|long]]##, 16 for a ##[[KeyPgLongint|longint]])##.

If you want to do the opposite, i.e. convert a hexadecimal string back into a number, the easiest way to do it is to prepend the string with ##"&H"##, and convert it to an integer type, using a function like ##[[KeyPgCint|Cint]]##, similarly to a normal numeric string. E.g. ##[[KeyPgCint|Cint]]("&HFF")##

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/strings/hex.bas"}}%%(freebasic)
'54321 is D431 in hex
Print Hex(54321)
Print Hex(54321, 2)
Print Hex(54321, 5)
%%
will produce the output:

%%D431
31
0D431
%%

{{fbdoc item="lang"}}
- The string type suffix "$" is required in the //[[CompilerOptlang|-lang qb]]// dialect.
- The string type suffix "$" is optional in the //[[CompilerOptlang|-lang fblite]]// dialect.
- The string type suffix "$" is ignored in the //[[CompilerOptlang|-lang fb]]// dialect, warn only with the //[[CompilerOptw|-w suffix]]// compile option (or //[[CompilerOptw|-w pedantic]]// compile option).

{{fbdoc item="diff"}}
- In QBASIC, there was no way to specify the number of digits returned.
- The size of the string returned was limited to 32 bits, or 8 hexadecimal digits.

{{fbdoc item="see"}}
- ##[[KeyPgBin|Bin]]##
- ##[[KeyPgOct|Oct]]##
- ##[[KeyPgValint|Valint]]##
- ##[[KeyPgVallng|Vallng]]##

{{fbdoc item="back" value="CatPgString|String Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode