BitValueString (String function): Difference between revisions
Jump to navigation
Jump to search
(6 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Template:String:BitValueString subtitle}} | {{Template:String:BitValueString subtitle}} | ||
This function returns the "value" of a bit in a string: 0 if the requested bit number is off, 1 if it is on. | |||
This | |||
==Syntax== | ==Syntax== | ||
{{Template:String:BitValueString syntax}} | {{Template:String:BitValueString syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%value</th><td>number</td></tr> | <tr><th>%value</th><td>Set to 0 if the requested but number was off, and 1 if it was on.</td></tr> | ||
<tr><th>string</th> | <tr><th>string</th><td>The string for which a bit is to be tested.</td></tr> | ||
<td>string</td></tr> | <tr><th>bitNumber</th><td>The bit number in the input string that is to be tested. Note that this is a bit number not a bit offset. So the first bit in the string is bit number 1.</td></tr> | ||
<tr><th>bitNumber</th> | |||
<td>number</td></tr> | |||
</table> | </table> | ||
==Usage notes== | |||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>Requesting a non-positive bit number, or a bit number past the the end of the string results in an [[InvalidBitNumber class|InvalidBitNumber exception]] being thrown.</li> | |||
<li>Since each byte in a string has 8 bits, the valid bit numbers range from 1 to the length of the string times 8. So a null (zero-length) string has no valid bits.</li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following example shows a bit in a string being tested based on a field value: | |||
<p class="code">%bitmap is string len 32 | |||
... | |||
for record %record | |||
if %bitmap:bitValueString(stateCode) eq 0 then | |||
... retrieve information for state | |||
%bitmap:bitSetString(statecode) | |||
end if | |||
end for | |||
</p> | |||
==See also== | ==See also== | ||
<table> | <table> | ||
Line 28: | Line 43: | ||
<td> | <td> | ||
<ul> | <ul> | ||
<li><var>[[BitClearString, BitFlipString, BitSetString (String functions)|BitClearString, BitFlipString, BitSetString]]</var> | <li><var>[[BitClearString, BitFlipString, and BitSetString (String functions)|BitClearString, BitFlipString, and BitSetString]]</var> | ||
<li><var>[[BitCountString (String function)|BitCountString]]</var> | <li><var>[[BitCountString (String function)|BitCountString]]</var> | ||
</ul> | </ul> |
Latest revision as of 20:33, 3 September 2015
Get bit value (0 or 1) in a string (String class)
[Introduced in Model 204 7.5]
This function returns the "value" of a bit in a string: 0 if the requested bit number is off, 1 if it is on.
Syntax
%value = string:BitValueString( bitNumber) Throws InvalidBitNumber
Syntax terms
%value | Set to 0 if the requested but number was off, and 1 if it was on. |
---|---|
string | The string for which a bit is to be tested. |
bitNumber | The bit number in the input string that is to be tested. Note that this is a bit number not a bit offset. So the first bit in the string is bit number 1. |
Usage notes
Usage notes
- Requesting a non-positive bit number, or a bit number past the the end of the string results in an InvalidBitNumber exception being thrown.
- Since each byte in a string has 8 bits, the valid bit numbers range from 1 to the length of the string times 8. So a null (zero-length) string has no valid bits.
Examples
The following example shows a bit in a string being tested based on a field value:
%bitmap is string len 32 ... for record %record if %bitmap:bitValueString(stateCode) eq 0 then ... retrieve information for state %bitmap:bitSetString(statecode) end if end for