1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-05 21:40:25 +00:00
QB64-PE/internal/help/%26H_%261.txt
Roland Heyder 6912727753 Update help files
Help file snapshot as of 07/31/2022.
2022-07-31 23:57:56 +02:00

97 lines
5.6 KiB
Plaintext

{{QBDLDATE:07-31-2022}}
{{QBDLTIME:23:54:05}}
The [[&H]] prefix denotes that an integer value is expressed in a Hexadecimal base 16 format. Every 2 digits represent a [[_BYTE]].
{{PageSyntax}}
: {{Parameter|a&}} = [[&H]]C0DEBA5E
{{PageDescription}}
* The base 16 numbering system uses hexadecimal digit values of 0 to F, where '''A''' = 10, '''B''' = 11, '''C''' = 12, '''D''' = 13, '''E''' = 14 and '''F''' = 15.
* Leading zero values can be omitted just like in decimal values as they add nothing to the return value.
* Decimal values returned can be any '''signed''' [[INTEGER]], [[LONG]] integer, or [[_INTEGER64]] value so use those type of variables when converting directly as shown above in the Syntax. The program [[ERROR Codes|"overflow"]] error limits are listed as:
:* [[_BYTE]]: 2 hex digits or a decimal value range from -128 to 127. [[_UNSIGNED]]: 0 to 255.
:* [[INTEGER]]: 4 hex digits or a decimal value range from -32,768 to 32,767. [[_UNSIGNED]]: 0 to 65535.
:* [[LONG]]: 8 hex digits or a decimal value range from -2,147,483,648 to 2,147,483,647. [[_UNSIGNED]]: 0 to 4294967295.
:* [[_INTEGER64]]: 16 hex digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
:* [[_UNSIGNED]] [[_INTEGER64]]: 0 to 18446744073709551615.
* The maximum hexadecimal value for each numerical type is the maximum number of digits listed above, each valued at '''F'''.
* Convert hexadecimal to [[LONG]] values by appending the values with the suffix '''&'''. Example: [[&H]]8000 = -32768: [[&H]]8000'''&''' = 32768
* [[LONG]] 32 bit [[_RGB]] values can be made using hexadecimal values from '''&HFF{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}''' with full [[_ALPHA]] only.
* [[LONG]] 32 bit [[_RGBA]] values can be made using hexadecimal values from '''&H00{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}''' with any [[_ALPHA]].
* Hexadecimal '''0x''' is often used to prefix [[HEX$]] port addresses in documentation. Replace '''0x''' with [[&H]] in QB64 or QBasic.
* To convert hexadecimal strings returned from [[HEX$]] with [[VAL]] you need to prefix the string with [[&H]] (for example, if the string is "FF" you should do {{InlineCode}}{{Cl|VAL}}("&HFF"){{InlineCodeEnd}} or {{InlineCode}}{{Cl|VAL}}("&H" + hexvalue$){{InlineCodeEnd}}.
{{PageExamples}}
;Example 1:The maximum hexadecimal values of decimal value -1 in each numerical type are:
{{CodeStart}}
c&& = -1: d& = -1: e% = -1: f%% = -1
hx$ = {{Cl|HEX$}}(f%%)
{{Cl|PRINT}} "Max hex {{Cl|_BYTE}} = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits ="; {{Cl|VAL}}("{{Cl|&H}}" + hx$)
hx$ = {{Cl|HEX$}}(e%)
{{Cl|PRINT}} "Max hex {{Cl|INTEGER}} = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits ="; {{Cl|VAL}}("{{Cl|&H}}" + hx$)
hx$ = {{Cl|HEX$}}(d&)
{{Cl|PRINT}} "Max hex {{Cl|LONG}} = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits ="; {{Cl|VAL}}("{{Cl|&H}}" + hx$)
hx$ = {{Cl|HEX$}}(c&&)
{{Cl|PRINT}} "Max hex {{Cl|_INTEGER64}} = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits ="; {{Cl|VAL}}("{{Cl|&H}}" + hx$)
hx$ = {{Cl|HEX$}}(9223372036854775807)
{{Cl|PRINT}} "Max {{Cl|_INTEGER64}} value = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits"
hx$ = {{Cl|HEX$}}(-9223372036854775808)
{{Cl|PRINT}} "Min {{Cl|_INTEGER64}} value = "; hx$; " with"; {{Cl|LEN}}(hx$); "digits"
{{CodeEnd}}
{{OutputStart}}
Max hex _BYTE = FF with 2 digits = 255
Max hex INTEGER = FFFF with 4 digits = 65535
Max hex LONG = FFFFFFFF with 8 digits = 4294967295
Max hex _INTEGER64 = FFFFFFFFFFFFFFFF with 16 digits =-1
Max _INTEGER64 value = 7FFFFFFFFFFFFFFF with 16 digits
Min _INTEGER64 value = 8000000000000000 with 16 digits
{{OutputEnd}}
;Example 2:Converting a decimal number to a binary string value using [[HEX$]].
{{CodeStart}}
{{Cl|FUNCTION}} BIN$ (n&)
h$ = {{Cl|HEX$}}(n&) 'get hexadecimal string value
{{Cl|FOR}} i = 1 {{Cl|TO}} {{Cl|LEN}}(h$) 'scan the HEX$ digits
{{Cl|SELECT CASE}} {{Cl|MID$}}(h$, i, 1) 'read each HEX$ digit
{{Cl|CASE}} "0": b$ = b$ + "0000"
{{Cl|CASE}} "1": b$ = b$ + "0001"
{{Cl|CASE}} "2": b$ = b$ + "0010"
{{Cl|CASE}} "3": b$ = b$ + "0011"
{{Cl|CASE}} "4": b$ = b$ + "0100"
{{Cl|CASE}} "5": b$ = b$ + "0101"
{{Cl|CASE}} "6": b$ = b$ + "0110"
{{Cl|CASE}} "7": b$ = b$ + "0111"
{{Cl|CASE}} "8": b$ = b$ + "1000"
{{Cl|CASE}} "9": b$ = b$ + "1001"
{{Cl|CASE}} "A": b$ = b$ + "1010"
{{Cl|CASE}} "B": b$ = b$ + "1011"
{{Cl|CASE}} "C": b$ = b$ + "1100"
{{Cl|CASE}} "D": b$ = b$ + "1101"
{{Cl|CASE}} "E": b$ = b$ + "1110"
{{Cl|CASE}} "F": b$ = b$ + "1111"
{{Cl|END SELECT}}
{{Cl|NEXT}} i
b$ = {{Cl|RIGHT$}}(b$, {{Cl|LEN}}(b$) - {{Cl|INSTR}}(b$, "1") + 1) 'eliminate leading zeroes
{{Cl|IF}} {{Cl|VAL}}(b$) {{Cl|THEN}} BIN$ = b$ {{Cl|ELSE}} BIN$ = "0" 'return zero if n& = 0
{{Cl|END FUNCTION}}
{{CodeEnd}}
{{small|Code by CodeGuy}}
;Explanation: Hexadecimal digits can be any value up to 15 which also corresponds to all four bits on in binary. The function above just adds every four bit binary string value together to return the binary value. After they are concatenated, the leading bit on is found by [[INSTR]] and everything from that point is kept removing the leading "0"'s.
;Note: Since QB64 2.1 (QB64 Team) respectively QBPE 0.5 (QB64 Phoenix Edition) the built-in [[_BIN$]] function should be used instead.
{{PageSeeAlso}}
* [[_BIN$]], [[HEX$]], [[OCT$]], [[STR$]]
* [[&B]] (binary), [[&O]] (octal), [[VAL]]
* [[Base Comparisons]]
* [[HEX$ 32 Bit Values]]
{{PageNavigation}}
[[Category:Final]]