&B: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "The '''&B''' prefix denotes that an integer value is expressed in a binary base 2 format using '''QB64''' only. {{PageSyntax}} :::: a& = '''&B1110110000111111''' * The base 2 numbering system uses binary digit values of 1 or 0, or bits on or bits off in computer register switches or memory. * Leading zero values '''can''' be omitted as they add nothing to the byte return value. * Eight binary digits would represent a one byte value ranging from 0 to 255. Four digit...") |
No edit summary Tag: Manual revert |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
The | The [[&B]] prefix denotes that an integer value is expressed in a Binary base 2 format. Every 8 digits represent a [[_BYTE]]. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: | : {{Parameter|a&}} = [[&B]]10010110 | ||
* The base 2 numbering system uses binary digit values of 1 | {{PageDescription}} | ||
* Leading zero values | * 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 in the Syntax. The program [[ERROR Codes|"overflow"]] error limits are listed as: | * 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: | ||
** [[INTEGER]]: 16 binary digits or a decimal value range from -32,768 to 32,767 | :* [[_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. | |||
* [[LONG]] values | :* [[_INTEGER64]]: 64 binary digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. | ||
* [[VAL]] | :* [[_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" | |||
{{ | |||
{{ | |||
{{ | |||
{{ | |||
{{Cl| | |||
{{Cl| | |||
{{Cl| | |||
{{Cl|PRINT}} | |||
{{Cl| | |||
{{Cl| | |||
{{Cl| | |||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} | ||
255 | 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}} | {{OutputEnd}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[ | * [[_BIN$]], [[HEX$]], [[OCT$]], [[STR$]] | ||
* [[&H]] (hexadecimal), [[&O]] (octal), [[VAL]] | |||
* [[ | * [[Base Comparisons]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 17:17, 25 November 2022
The &B prefix denotes that an integer value is expressed in a Binary base 2 format. Every 8 digits represent a _BYTE.
Syntax
- a& = &B10010110
Description
- 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 "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: &B1000000000000000 = -32768: &B1000000000000000& = 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 VAL("&B1101") or VAL("&B" + binvalue$).
Examples
- Example 1
- The maximum binary values of decimal value -1 in each numerical type are:
c&& = -1: d& = -1: e% = -1: f%% = -1 bi$ = _BIN$(f%%) PRINT "Max binary _BYTE = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(e%) PRINT "Max binary INTEGER = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(d&) PRINT "Max binary LONG = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(c&&) PRINT "Max binary _INTEGER64 = "; bi$; " with"; LEN(bi$); "digits ="; VAL("&B" + bi$) bi$ = _BIN$(9223372036854775807) PRINT "Max _INTEGER64 value = "; bi$; " with"; LEN(bi$); "digits" bi$ = _BIN$(-9223372036854775808) PRINT "Min _INTEGER64 value = "; bi$; " with"; LEN(bi$); "digits" |
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 |
See also