This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:sysprog:projects:wut2 [2018/02/13 17:25] – [bitmask.c] abratkov | notes:sysprog:projects:wut2 [2018/02/15 15:31] (current) – [rotate.c - Aaron Houghtaling] ahought2 | ||
---|---|---|---|
Line 9: | Line 9: | ||
=====endian.c===== | =====endian.c===== | ||
=====checksum.c===== | =====checksum.c===== | ||
- | =====twoscomp.c===== | + | =====twoscomp.c |
- | =====addition.c===== | + | |
- | =====bitmask.c===== | + | Last week, I had a broken, messy version of twoscomp.c. So I decided to rewrite it for wut2. Everything works except for only one string can be input at a time. |
+ | |||
+ | < | ||
+ | ./twoscomp -s " | ||
+ | 01101010 | ||
+ | |||
+ | ./twoscomp -v -s " | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 2 | ||
+ | Wordsize: | ||
+ | |||
+ | 10010110 -> 01101001 + 1 = 01101010 | ||
+ | |||
+ | ./twoscomp -w 4 -s " | ||
+ | 0111 | ||
+ | |||
+ | ./twoscomp -w 4 -v -s " | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 2 | ||
+ | Wordsize: | ||
+ | |||
+ | 1001 -> 0110 + 1 = 0111 | ||
+ | |||
+ | | ||
+ | Improper String Length. Wordsize is: 8 | ||
+ | String is: 6 characters long | ||
+ | |||
+ | ./twoscomp -b 10 -s " | ||
+ | 10 -> 246 | ||
+ | |||
+ | ./twoscomp -v -b 10 -s " | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 10 | ||
+ | Wordsize: | ||
+ | |||
+ | 10 -> 00001010 -> 11110101 + 1 = 11110110 -> 246 | ||
+ | |||
+ | ./twoscomp -v -w 4 -b 10 -s " | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 10 | ||
+ | Wordsize: | ||
+ | |||
+ | 10 -> 1010 -> 0101 + 1 = 0110 -> 6 | ||
+ | |||
+ | ./ | ||
+ | 124 -> 132 | ||
+ | |||
+ | ./ | ||
+ | 4294967172 | ||
+ | |||
+ | ./ | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 10 | ||
+ | Wordsize: | ||
+ | |||
+ | 124 -> 00000000000000000000000001111100 -> | ||
+ | 11111111111111111111111110000011 + 1 = | ||
+ | 11111111111111111111111110000100 -> | ||
+ | 4294967172 | ||
+ | |||
+ | ./ | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 10 | ||
+ | Wordsize: | ||
+ | |||
+ | 255 -> 11111111 -> 00000000 + 1 = 00000001 -> 1 | ||
+ | |||
+ | ./ | ||
+ | |||
+ | Segmentation fault | ||
+ | |||
+ | ./ | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 10 | ||
+ | Wordsize: | ||
+ | |||
+ | 6553 -> 00000000000000000001100110011001 -> | ||
+ | 11111111111111111110011001100110 + 1 = | ||
+ | 11111111111111111110011001100111 -> | ||
+ | 4294960743 | ||
+ | |||
+ | ./ | ||
+ | 123 -> 83 -> 193 -> 301 | ||
+ | |||
+ | ./ | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 8 | ||
+ | Wordsize: | ||
+ | |||
+ | 123 -> 83 -> 01010011 -> 10101100 + 1 = 10101101 -> 173 -> 255 | ||
+ | |||
+ | / | ||
+ | 1015 -> 175 -> 81 -> 51 //a = 10 f = 15, hence 1015 -> 175 | ||
+ | |||
+ | / | ||
+ | Verbose mode on: probably less ugly | ||
+ | |||
+ | Base: 16 | ||
+ | Wordsize: | ||
+ | |||
+ | 1015 -> 175 -> 10101111 -> 01010000 + 1 = 01010001 -> 81 -> 51 | ||
+ | |||
+ | ./twoscomp --help | ||
+ | ~~~~~twoscomp.c help page~~~~~ | ||
+ | |||
+ | Usage: ./twoscomp -s [STRING] [OPTION] | ||
+ | |||
+ | -q, --quiet | ||
+ | suppress all output | ||
+ | -V, --version | ||
+ | print version info | ||
+ | -v, --verbose | ||
+ | includes printout of all values specified by options | ||
+ | -D, --debug | ||
+ | | ||
+ | -s [STRING], --string[=STRING] | ||
+ | The string to be processed. | ||
+ | -d [DELIM], --delim[=DELIM] | ||
+ | Changes delimeter to [DELIM]. Defaults to space | ||
+ | -w [SIZE], --wordsize[=SIZE] | ||
+ | Sets the wordsize to [SIZE}. Defaults to 8 | ||
+ | Must be power of 2, between 4 and 128 | ||
+ | -b [BASE], --BASE[=BASE] | ||
+ | Changes the input/ | ||
+ | |||
+ | ./twoscomp -V | ||
+ | twoscomp Ver. 0.2 | ||
+ | |||
+ | //I also included my own -D debugging option | ||
+ | |||
+ | ./twoscomp -D -s " | ||
+ | Debug mode on~~: this is gonna be ugly | ||
+ | Verbose mode on: probably less ugly | ||
+ | ==================~~~~=============== | ||
+ | |||
+ | Size of Binary[]: 9 | ||
+ | Base: 2 | ||
+ | Wordsize: | ||
+ | Copied Input: | ||
+ | Size of Binary[]: 9 | ||
+ | Start of toBinary() | ||
+ | Base is 2 | ||
+ | After toBinary(), binary[] is: 10010110 | ||
+ | Start of twoscomp() | ||
+ | 10010110 -> 01101001 + 1 = | ||
+ | After twoscomp(), binary[] is: 01101010 | ||
+ | end of twoscomp() | ||
+ | Start of toDec() | ||
+ | |||
+ | End of toDec | ||
+ | After toDec, convDec is: 0 | ||
+ | After toDec(), binary[] is(should be unchanged): 01101010 | ||
+ | End of toBinary/ | ||
+ | Start of printnum() | ||
+ | 01101010 | ||
+ | End of printnum | ||
+ | </ | ||
+ | =====addition.c | ||
+ | |||
+ | 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' | ||
+ | |||
+ | The bare minimum operation is: ./addition -s " | ||
+ | |||
+ | where file contains " | ||
+ | |||
+ | 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, | ||
+ | |||
+ | ./addition -s "020 100" -b 10 | ||
+ | |||
+ | will print " | ||
+ | |||
+ | You can limit the size of the input/ | ||
+ | |||
+ | A space is the default delimiter, but a different character can be chosen as the delimiter using the -d option, as so: | ||
+ | |||
+ | ./addition -s " | ||
+ | |||
+ | or no delimiter if the -n option is chosen: | ||
+ | |||
+ | ./addition -s " | ||
+ | |||
+ | If the -C option is used, the program' | ||
+ | |||
+ | Using the -I option, you can specify an initial carry, like so: | ||
+ | |||
+ | ./addition -b 10 -s "010 210" -I " | ||
+ | |||
+ | which prints " | ||
+ | |||
+ | 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, | ||
+ | |||
+ | Some usage examples and their output (commands are on the first line, output on the following line(s): | ||
+ | |||
+ | < | ||
+ | ./addition -s " | ||
+ | 11111001 | ||
+ | |||
+ | ./addition -n -s " | ||
+ | Base is: 2 | ||
+ | Input unit is: 4 bits | ||
+ | Final carry is: 16 | ||
+ | |||
+ | 0010 | ||
+ | |||
+ | ./addition -b 8 -s "0012 0137" | ||
+ | 0151 | ||
+ | |||
+ | ./addition -7 -s " | ||
+ | 0111111 | ||
+ | |||
+ | echo "0x0e 0x02" | ./addition -b 16 | ||
+ | 0x10 | ||
+ | |||
+ | (here' | ||
+ | echo " | ||
+ | 0x10 | ||
+ | |||
+ | (notice how we get 0 because we hit the overflow) | ||
+ | ./addition -b 8 -7 -s "0177 0001" | ||
+ | 000 | ||
+ | |||
+ | ./addition -b 8 -7 -s "0177 0001" -I " | ||
+ | 003 | ||
+ | |||
+ | (add something over the size limit) | ||
+ | ./addition -b 10 -s "300 456" | ||
+ | Input exceeds size limit. | ||
+ | type "' | ||
+ | |||
+ | ./addition -b 16 -n -s " | ||
+ | 0x2a | ||
+ | |||
+ | echo "027 018" | ./addition -b 10 -I " | ||
+ | 46 | ||
+ | |||
+ | (file contains: "0010 0043" | ||
+ | ./addition -b 8 file | ||
+ | 053 | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | =====bitmask.c | ||
\\ | \\ | ||
+ | |||
+ | **Examples** \\ | ||
+ | |||
+ | **base 2 (default)** \\ | ||
./bitmask -M " | ./bitmask -M " | ||
10010010 \\ | 10010010 \\ | ||
10010001 \\ | 10010001 \\ | ||
- | ./bitmask -M " | + | **base 8** \\ |
+ | ./bitmask -M " | ||
66 \\ | 66 \\ | ||
66 \\ | 66 \\ | ||
- | ./bitmask -M " | ||
- | 66 \\ | ||
- | 66 \\ | ||
- | ./bitmask -M "31 -s " | + | **base 10**\\ |
+ | ./bitmask -M "31 -s " | ||
30 \\ | 30 \\ | ||
- | ./bitmask -M " | + | **base 16** \\ |
+ | ./bitmask -M " | ||
0xFE \\ | 0xFE \\ | ||
+ | **delimiter example** \\ | ||
+ | ./bitmask -M " | ||
+ | 66 \\ | ||
+ | 66 \\ | ||
+ | |||
+ | **word size example** | ||
+ | ./bitmask -M " | ||
+ | 65534 \\ | ||
+ | |||
+ | **Help** \\ | ||
+ | ./bitmask -h \\ \\ | ||
+ | Bitmask options: \\ | ||
+ | -M ' | ||
+ | -b ' | ||
+ | -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 ' | ||
+ | -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 ' | ||
+ | -q quiet, do not display anything to STDOUT \\ | ||
+ | -v verbose, display more information to STDOUT \\ | ||
+ | \\ | ||
+ | **Version** \\ | ||
+ | ./bitmask -V \\ | ||
+ | ./bitmask Awesome version 1.0 \\ | ||
+ | |||
+ | |||
+ | |||
+ | =====rotate.c - Aaron Houghtaling===== | ||
+ | |||
+ | rotate.c is a program that when given a set of bits will shift them left or right and carry over the removed bit and tacked onto the left or right side respectively. | ||
+ | |||
+ | Some Examples: | ||
+ | <cli> | ||
+ | lab46: | ||
+ | 1110 | ||
+ | |||
+ | lab46: | ||
+ | 1110 | ||
+ | |||
+ | lab46: | ||
+ | 1011 | ||
+ | |||
+ | lab46: | ||
+ | 1110 | ||
+ | |||
+ | lab46: | ||
+ | Version: rotate 2.0 | ||
+ | |||
+ | lab46: | ||
+ | 1110 | ||
+ | |||
+ | lab46: | ||
+ | 1110 | ||
+ | 110 | ||
+ | |||
+ | lab46: | ||
+ | 1110 110 | ||
+ | |||
+ | lab46: | ||
+ | Error: input does not match byte size! | ||
+ | |||
+ | lab46: | ||
+ | Usage: rotate [OPTION]... | ||
+ | Rotates bits from a given input based on args given | ||
+ | Rotates default behavior without arguments is to shift right by one bit | ||
+ | |||
+ | Optional Arguments: | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | -s [STRING] | ||
+ | | ||
+ | ex: -s "1011 1110" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | ex: 1011 1110 will process as only 1011 | ||
+ | -d [CHAR] | ||
+ | | ||
+ | | ||
+ | -w [#] set "#" | ||
+ | -L [#] rotate LEFT by "#" | ||
+ | -R [#] rotate RIGHT by "#" | ||
- | =====rotate.c===== | + | For further information contact: ahought2@corning-cc.edu |
+ | </ | ||
=====invert.c===== | =====invert.c===== | ||
+ | A bit-wise inversion is an operation where the end outputs the opposite bit of the beginning input. What this means is that the input bit of 1 will result in a 0 after this operation. | ||
+ | Example of outputs and error messages: | ||
+ | < | ||
+ | ./invert -s " | ||
+ | </ | ||
+ | < | ||
+ | echo " | ||
+ | </ | ||
+ | < | ||
+ | echo " | ||
+ | </ | ||
+ | < | ||
+ | echo " | ||
+ | </ | ||
+ | < | ||
+ | ./invert -V --> 0.0.2 | ||
+ | </ | ||
+ | < | ||
+ | ./invert --help | ||
+ | Usage: ./invert [OPTION]... [FILE]... | ||
+ | performs a bit inversion against a set of input values! | ||
+ | Arguments: | ||
+ | -h, --help | ||
+ | -V, --Version | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | </ |