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

60 lines
3.4 KiB
Plaintext

{{QBDLDATE:07-31-2022}}
{{QBDLTIME:23:54:02}}
The [[&B]] prefix denotes that an integer value is expressed in a Binary base 2 format. Every 8 digits represent a [[_BYTE]].
{{PageSyntax}}
: {{Parameter|a&}} = [[&B]]10010110
{{PageDescription}}
* The base 2 numbering system uses binary digit values of 0 and 1 only.
* 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]]: 8 binary digits or a decimal value range from -128 to 127. [[_UNSIGNED]]: 0 to 255.
:* [[INTEGER]]: 16 binary digits or a decimal value range from -32,768 to 32,767. [[_UNSIGNED]]: 0 to 65535.
:* [[LONG]]: 32 binary digits or a decimal value range from -2,147,483,648 to 2,147,483,647. [[_UNSIGNED]]: 0 to 4294967295.
:* [[_INTEGER64]]: 64 binary 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 binary value for each numerical type is the maximum number of digits listed above, each valued at '''1'''.
* Convert binary to [[LONG]] values by appending the values with the suffix '''&'''. Example: [[&B]]1000000000000000 = -32768: [[&B]]1000000000000000'''&''' = 32768
* To convert binary strings returned from [[_BIN$]] with [[VAL]] you need to prefix the string with [[&B]] (for example, if the string is "1101" you should do {{InlineCode}}{{Cl|VAL}}("&B1101"){{InlineCodeEnd}} or {{InlineCode}}{{Cl|VAL}}("&B" + binvalue$){{InlineCodeEnd}}.
{{PageExamples}}
;Example 1:The maximum binary values of decimal value -1 in each numerical type are:
{{CodeStart}}
c&& = -1: d& = -1: e% = -1: f%% = -1
bi$ = {{Cl|_BIN$}}(f%%)
{{Cl|PRINT}} "Max binary {{Cl|_BYTE}} = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits ="; {{Cl|VAL}}("{{Cl|&B}}" + bi$)
bi$ = {{Cl|_BIN$}}(e%)
{{Cl|PRINT}} "Max binary {{Cl|INTEGER}} = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits ="; {{Cl|VAL}}("{{Cl|&B}}" + bi$)
bi$ = {{Cl|_BIN$}}(d&)
{{Cl|PRINT}} "Max binary {{Cl|LONG}} = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits ="; {{Cl|VAL}}("{{Cl|&B}}" + bi$)
bi$ = {{Cl|_BIN$}}(c&&)
{{Cl|PRINT}} "Max binary {{Cl|_INTEGER64}} = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits ="; {{Cl|VAL}}("{{Cl|&B}}" + bi$)
bi$ = {{Cl|_BIN$}}(9223372036854775807)
{{Cl|PRINT}} "Max {{Cl|_INTEGER64}} value = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits"
bi$ = {{Cl|_BIN$}}(-9223372036854775808)
{{Cl|PRINT}} "Min {{Cl|_INTEGER64}} value = "; bi$; " with"; {{Cl|LEN}}(bi$); "digits"
{{CodeEnd}}
{{OutputStart}}
Max binary _BYTE = 11111111 with 8 digits = 255
Max binary INTEGER = 1111111111111111 with 16 digits = 65535
Max binary LONG = 11111111111111111111111111111111 with 32 digits = 4294967295
Max binary _INTEGER64 = 1111111111111111111111111111111111111111111111111111111111111111 with 64 digits =-1
Max _INTEGER64 value = 111111111111111111111111111111111111111111111111111111111111111 with 63 digits
Min _INTEGER64 value = 1000000000000000000000000000000000000000000000000000000000000000 with 64 digits
{{OutputEnd}}
{{PageSeeAlso}}
* [[_BIN$]], [[HEX$]], [[OCT$]], [[STR$]]
* [[&H]] (hexadecimal), [[&O]] (octal), [[VAL]]
* [[Base Comparisons]]
{{PageNavigation}}
[[Category:Final]]