Difference between revisions of "BIT"

From QB64 Wiki
Jump to navigation Jump to search
imported>Cyperium
m
imported>Cyperium
Line 6: Line 6:
  
  
::''Syntax, for example in regard to _DEFINE:'' [[_DEFINE]] LetterRange [[AS]] [ [[_UNSIGNED]] ] '''_BIT''' [*numberofbits]
+
::''Syntax, for example in regard to _DEFINE:'' {{KW|_DEFINE}} LetterRange {{KW|AS}} [{{KW|_UNSIGNED}}] '''_BIT''' [*numberofbits]
  
::''Syntax, for example in regard to DIM:'' [[DIM]] Variable [[AS]] [ [[_UNSIGNED]] ] '''_BIT''' [*numberofbits]
+
::''Syntax, for example in regard to DIM:'' {{KW|DIM}} Variable {{KW|AS}} [{{KW|_UNSIGNED}}] '''_BIT''' [*numberofbits]
  
  
 
''More information:''
 
''More information:''
  
* An [[_UNSIGNED]] _BIT can hold 0 or 1 instead of 0 and -1, if you set the numberofbits you can hold larger values depending on the number of bits you have set (_BIT * 8 can hold the same values as [[_BYTE]] for example) and the information below is comprimised if setting any number of bits other than 1.
+
* An {{KW|_UNSIGNED}} _BIT can hold 0 or 1 instead of 0 and -1, if you set the numberofbits you can hold larger values depending on the number of bits you have set (_BIT * 8 can hold the same values as {{KW|_BYTE}} for example) and the information below is comprimised if setting any number of bits other than 1.
 
* If you set the variable to any other number then the least significant bit of that number will be set as the variables number, if the bit is 1 (on) then the variable will be -1 and if the bit is 0 (off) then the variable will be 0.
 
* If you set the variable to any other number then the least significant bit of that number will be set as the variables number, if the bit is 1 (on) then the variable will be -1 and if the bit is 0 (off) then the variable will be 0.
 
*The least significant bit is the last bit on a string of bits (11111) since that bit will only add 1 to the value if set. The most significant bit is the first bit on a string of bits and changes the value more dramatically (significantly) if set on or off.
 
*The least significant bit is the last bit on a string of bits (11111) since that bit will only add 1 to the value if set. The most significant bit is the first bit on a string of bits and changes the value more dramatically (significantly) if set on or off.

Revision as of 02:52, 19 January 2010

The _BIT datatype can return only values of 0 (bit off) and -1 (bit on).


Syntax

AS [_UNSIGNED] _BIT *numberofbits


Syntax, for example in regard to _DEFINE: _DEFINE LetterRange AS [_UNSIGNED] _BIT [*numberofbits]
Syntax, for example in regard to DIM: DIM Variable AS [_UNSIGNED] _BIT [*numberofbits]


More information:

  • An _UNSIGNED _BIT can hold 0 or 1 instead of 0 and -1, if you set the numberofbits you can hold larger values depending on the number of bits you have set (_BIT * 8 can hold the same values as _BYTE for example) and the information below is comprimised if setting any number of bits other than 1.
  • If you set the variable to any other number then the least significant bit of that number will be set as the variables number, if the bit is 1 (on) then the variable will be -1 and if the bit is 0 (off) then the variable will be 0.
  • The least significant bit is the last bit on a string of bits (11111) since that bit will only add 1 to the value if set. The most significant bit is the first bit on a string of bits and changes the value more dramatically (significantly) if set on or off.
  • The _BIT datatype can be succesfully used as a Boolean (TRUE or FALSE) and it requires minimal amount of memory (the lowest amount possible actually, one byte can hold 8 bits, if you want to use bits in order to decrease memory usage, use them as arrays as a _BIT variable by itself allocates 4 bytes - DIM bitarray(800) AS _BIT uses 100 bytes).


  • Suffix Symbols The bit type suffix used below is above the shifted [1] key! NOT an apostrophy! Foreign keyboards may not have ´ as shifted [1] though.
You can define a bit on-the-fly by adding a ` after the variable, like this; variable` = -1
If you want a unsigned bit you can define it on-the-fly by adding ~` instead, like this; variable~` = 1
You can set the number of bits on the fly by just adding that number - this defines it as being two bits; variable`2 = -1


See also




Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page