This is an old revision of the document!
Input under each section examples of your program running using different options
addition.c is an addition program that uses bitwise logic to add two numbers together. The absolute size limit for numbers is 255, though it may be smaller if a smaller word size (either 7 bits or a nibble) is chosen. Sums can go over this, but won't be reported in the results. If you want the carry, there's an option for that.
The bare minimum operation is: ./addition -s “10001000 00101000” or echo “10001000 00101000” | ./addition or ./addition file
where file contains “10001000 00101000” (minus quotes)… note that if other options are specified, file must follow all of the options or the program will complain.
By default, the program expects 8-bits of binary input for each number to be added. If you have less or more than this (i.e. type “1001 0100” instead of the other string up above), it will complain.
There are some additional options, depending on what type of numbers you want to add. You can change base to 8, 10, or 16 by specifying -b 8 or -b 10 or -b 16 on the command line (-b 2 is also possible but unnecessary, as base 2 is the default). For example,
./addition -s “020 100” -b 10
will print “120”
You can limit the size of the input/output by using the -4, -7, or -8 (default) options, which will cause the program to expect that number of bits as input. Bits are from the computer's perspective. Choosing the -4 option will limit binary input to the range 0000-1111, octal input 000-017, decimal 00-15, or hexadecimal 0x00-0x0F. Going over these limits will cause an error.
A space is the default delimiter, but a different character can be chosen as the delimiter using the -d option, as so:
./addition -s “1000A0100” -d 'A' -4
or no delimiter if the -n option is chosen:
./addition -s “10000100” -n -4
If the -C option is used, the program's return value will be the final carry. This can be useful if the sum overflows the 0-255 size limit.
Using the -I option, you can specify an initial carry, like so:
./addition -b 10 -s “010 210” -I “005”
which prints “225”
The -h/-? option will display a more detailed usage guide. The -q option makes all output quiet, while the -v option will print information about the base, word size, and initial carry.
The -V option prints version information, in this case “wut.2”
Some usage examples and their output (commands are on the first line, output on the following line(s):
./addition -s "10011000 01100001" 11111001 ./addition -n -s "10011001" -4 -C -v Base is: 2 Input unit is: 4 bits Final carry is: 16 0010 ./addition -b 8 -s "0012 0137" 0151 ./addition -7 -s "0101111 0010000" 0111111 echo "0x0e 0x02" | ./addition -b 16 0x10 (here's a fun one: using 'x' as the delimiter for hexadecimal numbers won't cause errors!) echo "0x0ex0x02" | ./addition -b 16 -d 'x' 0x10 (notice how we get 0 because we hit the overflow) ./addition -b 8 -7 -s "0177 0001" 000
Examples
base 2 (default)
./bitmask -M “10110111” -s “10011010 11010001”
10010010
10010001
base 8
./bitmask -M “66” -s “77 77” -b 8
66
66
base 10
./bitmask -M “31 -s “30” -b 10
30
base 16
./bitmask -M “FE” -s “FF” -b 16
0xFE
delimiter example
./bitmask -M “66” -s “77s77” -b 8 -d “s”
66
66
word size example
./bitmask -M “65535” -s “65534” -w128 -b10
65534
Help
./bitmask -h
Bitmask options:
-M 'BITMASK' specify bitmask value for processing (required)
-b 'BASE' input/output base (of 2, 8, 10, or 16; base 2 is default)
-w # set wordsize (power of 2 between 4 and 128, 8 is default)
Options displayed here for help:
-h display usage information and exit
-V display version information and exit
-s 'STRING' specify STRING as value to process
-4 set nibble as processing unit/word size
-7 set byte/word as 7-bits
-8 set byte/word as 8-bits (default)
-n no delimiter between processing units
-d 'CHAR' use CHAR as delimiter between processing units (space is default)
-q quiet, do not display anything to STDOUT
-v verbose, display more information to STDOUT
Version
./bitmask -V
./bitmask Awesome version 1.0