Skip to content

shellfire-dev/byte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

byte: functions module for shellfire

This module provides an immature framework for manipulating byte and bit values from shell script.

Compatibility

Overview

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"
fi

Importing

To 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 --update

You 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.

Namespace byte

To use in code

If calling from another shellfire module, add to your shell code the line

core_usesIn byte

in 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
	…
}

Functions


byte_isBitSet()

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.


byte_printBinary()

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.


byte_setBit()

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.

About

byte functions module for shellfire

Resources

License

Stars

Watchers

Forks

Packages

No packages published