byte: functions module for shellfire
This module provides an immature framework for manipulating byte and bit values from shell script.
- Tag
release_2015.0117.1750-1is compatible with shellfire releaserelease_2015.0117.1750-1.
For example, to test if a bit is set:-
# tests if bit 1 (zero based) of value 3 is set
if byte_isBitSet 3 1; then
echo "Success"
fiTo import this module, add a git submodule to your repository. From the root of your git repository in the terminal, type:-
mkdir -p lib/shellfire
cd lib/shellfire
git submodule add "https://github.com/shellfire-dev/byte.git"
cd -
git submodule init --updateYou may need to change the url https://github.com/shellfire-dev/byte.git" above if using a fork.
You will also need to add paths - include the module paths.d.
If calling from another shellfire module, add to your shell code the line
core_usesIn bytein the global scope (ie outside of any functions). A good convention is to put it above any function that depends on functions in this module. If using it directly in a program, put this line inside the _program() function:-
_program()
{
core_usesIn byte
…
}| Parameter | Value | Optional |
|---|---|---|
value |
Byte value as a number. Signed or unsigned irrelevant. | No |
bitIndex |
Zero based bit between 7 and 0 inclusive (not validated) | No |
Return code is zero if set, non-zero it otherwise.
| Parameter | Value | Optional |
|---|---|---|
value |
Byte value as a number. Signed or unsigned irrelevant. | No |
Writes eight binary digits of 0 or 1 to standard out.
| Parameter | Value | Optional |
|---|---|---|
value |
Byte value as a number. Signed or unsigned irrelevant. | No |
bitIndex |
Zero based bit between 7 and 0 inclusive (not validated) | No |
Takes the value value, sets the bit bitIndex to 1 and writes the resultant value to standard out.