1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-29 11:40:38 +00:00
QB64-PE/internal/help/HEX$.txt
SteveMcNeill 33adc04fc4 Add temp folder to repo. It's necessary as well!
Just more initial setting on... nothing much to see here.
2022-04-28 13:39:56 -04:00

71 lines
2.7 KiB
Plaintext

The [[HEX$]] function returns the base 16 hexadecimal representation of an [[INTEGER]], [[LONG]] or [[_INTEGER64]] value as a [[STRING]].
{{PageSyntax}}
:{{Parameter|result$}} = [[HEX$]]({{Parameter|decimalNumber}})
{{PageDescription}}
* The function returns the string hexadecimal (base-16) representation of {{Parameter|decimalNumber}}.
* The function does not return a leading sign space so [[LTRIM$]] is not necessary.
<!-- Confusing hack hidden: * Can be used in place of [[STR$]] to trim both sides of positive decimal values 0 to 9 only.}} -->
* [[VAL]] can convert the string value back to a decimal value by prefixing the string return with "&H": {{InlineCode}}dec = VAL("&H" + hexvar$){{InlineCodeEnd}}.
{{PageExamples}}
''Example 1:'' Comparing decimal, hexadecimal and octal string values 0 to 15.
{{CodeStart}} '' ''
LOCATE 2, 20: PRINT " Decimal | Hexadecimal | Octal "
LOCATE 3, 20: PRINT "-----------+-------------+--------"
template$ = " \ \ | \\ | \\ "
FOR n% = 0 TO 15
LOCATE 4 + n%, 20: {{Cl|PRINT USING}} template$; {{Cl|STR$}}(n%); {{Cl|HEX$}}(n%); {{Cl|OCT$}}(n%)
NEXT n% '' ''
{{CodeEnd}}
{{OutputStart}}
Decimal | Hexadecimal | Octal
-----------+-------------+--------
0 | 0 | 0
1 | 1 | 1
2 | 2 | 2
3 | 3 | 3
4 | 4 | 4
5 | 5 | 5
6 | 6 | 6
7 | 7 | 7
8 | 8 | 10
9 | 9 | 11
10 | A | 12
11 | B | 13
12 | C | 14
13 | D | 15
14 | E | 16
15 | F | 17
{{OutputEnd}}
''Note:'' Decimal [[STR$]] values contain a leading sign space so values require an extra space in the template using the slash format.
''Example 2:'' Converting hex value to decimal.
{{CodeStart}}
h$ = {{Cl|HEX$}}(255)
{{Cl|PRINT}} "Hex: "; h$
{{Cl|PRINT}} "Converting Hex value to Decimal:"; {{Cl|VAL}}("&H" + h$)
{{CodeEnd}}
{{OutputStart}}
Hex: FF
Converting Hex value to Decimal: 255
{{OutputEnd}}
{{PageSeeAlso}}
* [[OCT$]], [[STR$]], [[VAL]]
* [[&H]] {{text|(hexadecimal)}}, [[&O]] {{text|(octal)}}, [[&B]] {{text|(binary)}}
* [[Base Comparisons]]
* [[HEX$ 32 Bit Values]]
{{PageNavigation}}
<