A 08/resistance-calculator/resistance-calculator => 08/resistance-calculator/resistance-calculator +0 -0
M 08/resistance-calculator/resistance-calculator.cpp => 08/resistance-calculator/resistance-calculator.cpp +11 -12
@@ 10,9 10,8 @@
#define MAX_RESISTORS 100
-int i = 0; // counter
-float resistor; // resistor being input
-float biggest_resistor = 0; // resistance of most resistive resistor
+int resistor_count = 0; // counter
+float resistors[MAX_RESISTORS]; // resistor being input
float total_resistance; // total resistance across network in ohms
int main() {
@@ 20,24 19,24 @@ int main() {
while(true) {
// user input
- std::cout << "Resistance of R" << i+1 << " in ohms: ";
- std::cin >> resistor;
+ std::cout << "Resistance of R" << resistor_count+1 << " in ohms: ";
+ std::cin >> resistors[resistor_count];
// exit condition
- if(resistor == 0) {
+ if(resistors[resistor_count] == 0) {
break;
}
- // determine biggest resistor
- if(resistor > biggest_resistor)
- biggest_resistor = resistor;
-
// increment counter
- i++;
+ resistor_count++;
}
// calculate total resistance
- total_resistance = biggest_resistor / (i+1);
+ for(int i = 0; i < resistor_count; i++) {
+ total_resistance += 1 / resistors[i];
+ }
+
+ total_resistance = 1 / total_resistance;
// print total resistance
std::cout << "Total resistance across network: " << total_resistance << " ohms\n";
A 09/count-in-array/Makefile => 09/count-in-array/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for program count-in-array
+
+# Turn on debugging
+CXXFLAGS=-g
+
+count-in-array:count-in-array.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:count-in-array
+ rm $^
+
+run:count-in-array
+ ./$^
A 09/count-in-array/count-in-array.cpp => 09/count-in-array/count-in-array.cpp +63 -0
@@ 0,0 1,63 @@
+/****************************************
+* count-in-array -- count the amount of *
+* times a number appears in an array *
+* Usage: Input array items at prompt, *
+* and 0 to stop. Then enter the *
+* number you are searching for *
+****************************************/
+
+#include <iostream>
+
+
+/****************************************
+* count -- count the amount of times a *
+* number appears in an array *
+* Parameters: *
+* number -- number to search for *
+* array -- array to search in *
+* length -- length of array *
+* Returns: *
+* amount of times n appears in array *
+****************************************/
+int count(float number, float* array, int length) {
+ int number_count = 0; // number of times number appears in array
+
+ // iterate through each item in array, comparing it with the number searching for
+ for(int i = 0; i < length; i++) {
+ if(array[i] == number)
+ number_count++;
+ }
+
+ return(number_count);
+}
+
+int main() {
+ float number; // number to search for
+ int length; // length of array
+ int number_count; // number of times number appears in array
+
+ int count(float number, float array[], int length); // number count function prototype
+
+ // print program name
+ std::cout << "count-in-array\n";
+
+ // get array items and number to search for
+ std::cout << "Enter array length: ";
+ std::cin >> length;
+
+ float* array = new float[length]; // array to search through
+
+ for(int i = 0; i < length; i++) {
+ std::cout << "Enter item " << i << ": ";
+ std::cin >> array[i];
+ }
+
+ std::cout << "Enter number to search for: ";
+ std::cin >> number;
+
+ // determine number count
+ number_count = count(number, array, length);
+
+ std::cout << number << " appears " << number_count << " times\n";
+}
+
A 09/count-in-array/count-in-array.md => 09/count-in-array/count-in-array.md +23 -0
@@ 0,0 1,23 @@
+# count-in-array
+
+> Count the number of times 'n' appears in an array
+> Users' Specification
+> Jan 20, 2023 Bobby Hamblin
+
+Counts the amount of times a number `n` appears in an array.
+
+Enter array items at prompt, and enter 0 to stop entering items in the
+array. Then enter which number you are searching for.
+
+## Example
+
+> Enter array length: *6*
+> Enter item 1: *5*
+> Enter item 2: *4*
+> Enter item 3: *5*
+> Enter item 4: *9*
+> Enter item 5: *6*
+> Enter item 6: *5*
+> Enter number to search for: *5*
+> 5 appears 3 times
+
A 09/hash/Makefile => 09/hash/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for program hash
+
+# Turn on debugging
+CXXFLAGS=-g
+
+hash:hash.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:hash
+ rm $^
+
+run:hash
+ ./$^
A 09/hash/hash.cpp => 09/hash/hash.cpp +46 -0
@@ 0,0 1,46 @@
+/****************************************
+* hash -- encodes a string with a *
+* primitive hash *
+* Usage: Input a string at the prompt *
+****************************************/
+
+#include <iostream>
+#include <string>
+
+/****************************************
+* create_hash -- create a hash using *
+* the ascii values of each character *
+* Parameters: *
+* input -- string to encode *
+* Returns: *
+* primitive integer hash of string *
+****************************************/
+int create_hash(std::string input) {
+ int hash = 0; // primitive hash of string
+
+ // iterate through each item in array, comparing it with the number searching for
+ for(int i = 0; i < input.length(); i++) {
+ hash += input[i];
+ }
+
+ return(hash);
+}
+
+int main() {
+ std::string input; // input string
+ int hash; // primitive hash
+
+ int create_hash(std::string input);
+
+ // print program name
+ std::cout << "hash\n";
+
+ std::cout << "Input a string: ";
+ std::cin >> input;
+
+ // determine number count
+ hash = create_hash(input);
+
+ std::cout << hash << "\n";
+}
+
A 09/hash/hash.md => 09/hash/hash.md +15 -0
@@ 0,0 1,15 @@
+# hash
+
+> Encodes a string by adding together the character values
+> Users' Specification
+> Jan 26, 2023 Bobby Hamblin
+
+For a given input string, this program returns a primitive hash code by
+adding up the value of each character in the string. The decimal ASCII
+value of each character is used and then added together to result in the
+output.
+
+## Example
+
+> Input a string: *This is a test string*
+> 408
A 09/kebab-to-snake-case/Makefile => 09/kebab-to-snake-case/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for program kebab-to-snake-case
+
+# Turn on debugging
+CXXFLAGS=-g
+
+kebab-to-snake-case:kebab-to-snake-case.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:kebab-to-snake-case
+ rm $^
+
+run:kebab-to-snake-case
+ ./$^
A 09/kebab-to-snake-case/kebab-to-snake-case.cpp => 09/kebab-to-snake-case/kebab-to-snake-case.cpp +51 -0
@@ 0,0 1,51 @@
+/****************************************
+* kebab-case-to-snake-case -- converts *
+* kebab-case text to snake_case text *
+* Usage: Input string to be converted *
+* at prompt *
+****************************************/
+
+#include <iostream>
+#include <string>
+
+/****************************************
+* convert_to_snake_case -- converts *
+* text to snake_case *
+* Parameters: *
+* kebab_case_text -- text to convert *
+* Returns: *
+* snake case text *
+****************************************/
+std::string convert_to_snake_case(std::string kebab_case_text) {
+ std::string snake_case_text; // converted text
+
+ for(int i = 0; i < kebab_case_text.length(); i++) {
+ // if character is a hyphen, convert to an underscore
+ if(kebab_case_text[i] == '-') {
+ snake_case_text.push_back('_');
+ } else {
+ snake_case_text.push_back(kebab_case_text[i]);
+ }
+ }
+
+ return(snake_case_text);
+}
+
+int main() {
+ std::string kebab_case_text; // text to be converted
+ std::string snake_case_text; // converted text
+
+ std::string convert_to_snake_case(std::string kebab_case_text); // converter function prototype
+
+ // print program name
+ std::cout << "kebab-to-snake-case\n";
+
+ // get strings
+ std::cout << "Input text in kebab-case: ";
+ std::getline(std::cin, kebab_case_text);
+
+ // get and display begins status
+ snake_case_text = convert_to_snake_case(kebab_case_text);
+ std::cout << snake_case_text << "\n";
+}
+
A 09/kebab-to-snake-case/kebab-to-snake-case.md => 09/kebab-to-snake-case/kebab-to-snake-case.md +16 -0
@@ 0,0 1,16 @@
+# kebab-to-snake-case
+
+> Converts text from kebab-case to snake_case
+> Users' Specification
+> Jan 20, 2023 Bobby Hamblin
+
+Converts text from hyphen-separated kebab-case to underscore\_seperated
+snake\_case. Takes a string of input from the user, converts it, and
+prints the new string.
+
+## Example
+
+> kebab-case-to_snake_case
+> Input text in kebab-case: *This-text-is-to-be-converted*
+> This_text_is_to_be_converted
+
A 09/maximum/Makefile => 09/maximum/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for program maximum
+
+# Turn on debugging
+CXXFLAGS=-g
+
+maximum:maximum.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:maximum
+ rm $^
+
+run:maximum
+ ./$^
A 09/maximum/maximum.cpp => 09/maximum/maximum.cpp +55 -0
@@ 0,0 1,55 @@
+/****************************************
+* maximum -- find the largest number in *
+* in a given array *
+* Usage: Input array items at prompt, *
+* and 0 to stop. *
+****************************************/
+
+#include <iostream>
+
+/****************************************
+* maximum -- find maximum value in an *
+* array *
+* Parameters: *
+* array -- array to search in *
+* Returns: *
+* largest number in array *
+****************************************/
+int maximum(float* array) {
+ float largest_number = 0; // largest number in array
+
+ // iterate through each item in array, comparing it with the current largest number
+ for(int i = 0; i < sizeof(array); i++) {
+ if(array[i] > largest_number)
+ largest_number = array[i];
+ }
+
+ return(largest_number);
+}
+
+int main() {
+ int biggest_number; // number of times number appears in array
+ float* array = new float[100]; // array to search through
+ int i = 0; // counter for number of items in array
+
+ int maximum(float array[]); // maximum function prototype
+
+ // print program name
+ std::cout << "maximum\n";
+
+ while(1) {
+ std::cout << "Enter item " << i+1 << ": ";
+ std::cin >> array[i];
+
+ if(array[i] == 0)
+ break;
+
+ i++; // increment counter
+ }
+
+ // determine biggest number
+ biggest_number = maximum(array);
+
+ std::cout << "The biggest number is " << biggest_number << "\n";
+}
+
A 09/maximum/maximum.md => 09/maximum/maximum.md +23 -0
@@ 0,0 1,23 @@
+# maximum
+
+> Find the maximum value in an array
+> Users' Specification
+> Jan 26, 2023 Bobby Hamblin
+
+For a given array of floating-point numbers, this program returns the
+maximum value in that array.
+
+Enter array items at prompt, and enter 0 to stop entering items in the
+array.
+
+## Example
+
+> Enter item 1: *5*
+> Enter item 2: *4*
+> Enter item 3: *5*
+> Enter item 4: *9*
+> Enter item 5: *19*
+> Enter item 6: *5*
+> The biggest number is 19
+
+
M 09/strbegins/strbegins.cpp => 09/strbegins/strbegins.cpp +32 -27
@@ 1,48 1,53 @@
/****************************************
-* word-count -- count words in a string *
-* Usage: Input sentence at prompt *
+* strbegins -- returns true if string1 *
+* begins string2 *
+* Usage: Input strings at prompt *
****************************************/
#include <iostream>
/****************************************
-* count_words -- count words in a *
-* string *
+* begins -- determines whether string1 *
+* begins string2 *
* Parameters: *
-* sentence -- string to count words *
+* string1 -- text to begin *
+* string2 -- text to test *
* Returns: *
-* number of words in string *
+* whether string1 begins string2 *
****************************************/
-int count_words(std::string sentence) {
- int word_count = 0; // word count
-
- // increment word count if sentence contains text
- if(sentence != "")
- word_count++;
-
- // iterate through each character in string, incrementing word count for each
- for(int i = 0; i < sentence.length(); i++) {
- if(sentence[i] == ' ')
- word_count++;
+bool begins(std::string string1, std::string string2) {
+ bool does_begin = true; // whether string1 begins string2
+
+ for(int i = 0; i < string1.size(); i++) {
+ // if characters don't match, string doesn't begin
+ if(string2[i] != string1[i]) {
+ does_begin = false;
+ break;
+ }
}
- return(word_count);
+ return(does_begin);
}
int main() {
- std::string sentence; // sentence to count
- int words; // number of words in sentence
+ std::string string1; // determiner string
+ std::string string2; // test string
+ bool does_begin; // whether string1 begins string2 or not
- int count_words(std::string sentence); // word count function prototype
+ bool begins(std::string string1, std::string string2); // begins function prototype
// print program name
- std::cout << "word-count\n";
+ std::cout << "strbegins\n";
+
+ // get strings
+ std::cout << "String 1: ";
+ std::getline(std::cin, string1);
+ std::cout << "String 2: ";
+ std::getline(std::cin, string2);
- // get and display word count
- std::cout << "Input sentence to count: ";
- std::getline(std::cin, sentence);
- words = count_words(sentence);
- std::cout << "The sentence input has " << words << " words\n";
+ // get and display begins status
+ does_begin = begins(string1, string2);
+ std::cout << does_begin << "\n";
}
M 09/strbegins/strbegins.md => 09/strbegins/strbegins.md +10 -5
@@ 1,14 1,19 @@
# strbegins
-> Count words in a string
+> Returns true if string1 begins string2
> Users' Specification
> Jan 20, 2023 Bobby Hamblin
-Counts the number of words in an input string. A word is defined as a
-collection of characters terminated by a space.
+A function and test program to determine whether a first input string
+begins a second input string or not
## Example
-> Enter sentence to count: *This is an example sentence *
-> The sentence input has 5 words
+> strbegins
+> String 1: *this is a test*
+> String 2: *this is also a test*
+> 1
+> String 1: *this is another test*
+> String 2: *testing string number 2*
+> 0
A 10/divisible-by-ten/divisible-by-ten.h => 10/divisible-by-ten/divisible-by-ten.h +9 -0
@@ 0,0 1,9 @@
+/****************************************
+* divisible-by-ten -- macro returns *
+* whether an input number is evenly *
+* divisible by ten or not *
+****************************************/
+
+// Define the RETURN_STATUS type
+#define DIVISIBLE_BY_TEN(x) if(((x) % 10) == 0) {return(true)} else {return(false)};
+
A 10/divisible-by-ten/divisible-by-ten.md => 10/divisible-by-ten/divisible-by-ten.md +9 -0
@@ 0,0 1,9 @@
+# divisible-by-ten
+
+> A macro to return whether a value is divisible by ten
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+As the short description implies, a singular macro that returns true if
+a its parameter is divisible by 10, and false otherwise
+
A 10/is-digit/is-digit.h => 10/is-digit/is-digit.h +8 -0
@@ 0,0 1,8 @@
+/****************************************
+* is-digit -- macros to determine if a *
+* value is a decimal or hex digit *
+****************************************/
+
+#define IS_DIGIT(x) (std::isdigit(x) || value == '.')
+#define IS_HEX(x) (input[0] == '0' && input[1] == 'x')
+
A 10/is-digit/is-digit.md => 10/is-digit/is-digit.md +9 -0
@@ 0,0 1,9 @@
+# is-digit
+
+> Macros to return whether its argument is a digit
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+Two macros, IS\_DIGIT and IS\_HEX that determine whether a given value
+is a decimal or hexadecimal digit. The hexadecimal macro references the
+decimal macro.
A 10/return-status/return-status.h => 10/return-status/return-status.h +17 -0
@@ 0,0 1,17 @@
+/****************************************
+* return-status -- macro set to *
+* implement a RETURN_STATUS type *
+****************************************/
+
+// Define the RETURN_STATUS type
+typedef int RETURN_STATUS;
+
+// Define the RETURN_SUCCESS, RETURN_WARNING, and RETURN_ERROR values
+#define RETURN_SUCCESS 0
+#define RETURN_WARNING 1
+#define RETURN_ERROR 2
+
+// Define the CHECK_RETURN_FATAL macro
+#define CHECK_RETURN_FATAL(status) if((status) == 1) {return(true);};
+
+
A 10/return-status/return-status.md => 10/return-status/return-status.md +11 -0
@@ 0,0 1,11 @@
+# return-status
+
+> A set of macros to define a RETURN_STATUS type
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+A set of macros to define a type called RETURN\_STATUS with the following
+values: RETURN\_SUCCESS, RETURN\_WARNING, and RETURN\_ERROR. Also
+implements a macro, CHECK\_RETURN\_FATAL that takes a RETURN\_STATUS as
+an argument and returns true if there is a fatal error.
+
A 10/swap-integers/swap-integers.h => 10/swap-integers/swap-integers.h +7 -0
@@ 0,0 1,7 @@
+/****************************************
+* swap-integers -- macro to swap two *
+* input integers *
+****************************************/
+
+#define SWAP_INTEGERS(x, y) int temp = (a); (a) = (b); (b) = temp;
+
A 10/swap-integers/swap-integers.md => 10/swap-integers/swap-integers.md +7 -0
@@ 0,0 1,7 @@
+# swap-integers
+
+> Macro to swap two integer inputs
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+This macro swaps the two integers input.
A 11/bit-shift/Makefile => 11/bit-shift/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for progam bit-shift
+
+# Turn on debugging
+CXXFLAGS = -g
+
+bit-shift:bit-shift.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:bit-shift
+ rm $^
+
+run:bit-shift
+ ./$^
A 11/bit-shift/bit-shift.cpp => 11/bit-shift/bit-shift.cpp +66 -0
@@ 0,0 1,66 @@
+/****************************************
+* bit-shift -- shift bits to the left *
+* Usage: Input an integer at the prompt *
+****************************************/
+
+#include <iostream>
+
+/****************************************
+* shift_bits -- shifts all bits to the *
+* left *
+* Parameters *
+* integer -- integer to shift *
+* Returns *
+* shifted integer *
+****************************************/
+int shift_bits(int integer){
+ int shifted_integer = integer; // integer after shift
+ int mask = 1 << 31; // Create a mask of the leftmost bit
+
+ // shift each high bit to the left
+ while ((shifted_integer & mask) == 0) {
+ shifted_integer <<= 1; // Shift the number one bit to the left
+ // mask >>= 1; // Shift the mask one bit to the right
+ }
+
+ return(shifted_integer);
+}
+
+/****************************************
+* print_bits -- print all bits in an *
+* integer *
+* Parameters *
+* integer -- integer to print *
+****************************************/
+void print_bits(int integer) {
+ for (int i = 0; i < sizeof(integer) * 32; i++) {
+ std::cout << ((integer >> i) & 1);
+ }
+}
+
+int main() {
+ int integer; // integer to shift
+ int shifted_integer; // integer after shift
+
+ // get user input
+ std::cout << "Enter an integer: ";
+ std::cin >> integer;
+
+ // print bits of input integer
+ print_bits(integer);
+ std::cout << "\n";
+
+ // shift the integer
+ shifted_integer = shift_bits(integer);
+
+ // print bits of shifted int
+ print_bits(shifted_integer);
+ std::cout << "\n";
+
+ // print shifted value as decimal
+ std::cout << shifted_integer << " ";
+ std::cout << "\n";
+
+ return(0);
+}
+
A 11/bit-shift/bit-shift.md => 11/bit-shift/bit-shift.md +17 -0
@@ 0,0 1,17 @@
+# bit-shift
+
+> Shifts bits in an integer to the left end
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+Given an integer, this program shifts all bits set to `1` to the left
+end.
+
+Enter an integer at the prompt.
+
+## Example
+
+> Enter an integer: *86*
+> 01010110
+> 11110000
+> 240
A 11/count-bits/Makefile => 11/count-bits/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for progam count-bits
+
+# Turn on debugging
+CXXFLAGS = -g
+
+count-bits:count-bits.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:count-bits
+ rm $^
+
+run:count-bits
+ ./$^
A 11/count-bits/count-bits.cpp => 11/count-bits/count-bits.cpp +41 -0
@@ 0,0 1,41 @@
+/****************************************
+* count-bits -- count bits in integer *
+* Usage: Enter an integer at the prompt *
+****************************************/
+
+#include <iostream>
+
+/****************************************
+* count-bits -- count bits in integer *
+* Parameters *
+* integer -- integer to test *
+* Returns *
+* number of bits set to 1 in integer *
+****************************************/
+inline int count_bits(const int integer){
+ int total_bits; // total bits in integer
+
+ for(int i = 0; i < sizeof(integer)*8; i++) {
+ int bit = (integer >> i); // bit being currrently counted
+ if(bit & 1) {
+ total_bits++;
+ }
+ }
+ return(total_bits);
+}
+
+int main() {
+ int integer; // integer to test
+ int total_bits; // bits in integer
+
+ // get user input
+ std::cout << "Enter an integer: ";
+ std::cin >> integer;
+
+ // count and print bits in integer
+ total_bits = count_bits(integer);
+ std::cout << total_bits << "\n";
+
+ return(0);
+}
+
A 11/count-bits/count-bits.md => 11/count-bits/count-bits.md +13 -0
@@ 0,0 1,13 @@
+# count-bits
+
+> Count set bits in an integer
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+Given an integer, it counts the number of bits that are set to 1 in
+that integer.
+
+## Example
+
+> Enter an integer: *5*
+> 2
A 11/graph/Makefile => 11/graph/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for progam graph
+
+# Turn on debugging
+CXXFLAGS = -g
+
+graph:graph.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:graph
+ rm $^
+
+run:graph
+ ./$^
A 11/graph/graph.cpp => 11/graph/graph.cpp +100 -0
@@ 0,0 1,100 @@
+/****************************************
+* graph -- bitmapped graphics engine *
+****************************************/
+
+#include <iostream>
+#include <cassert>
+
+const int X_SIZE = 16; // size of the array in X direction
+const int Y_SIZE = 16; // size of the array in Y direction
+
+/*
+* We use X_SIZE/8 since we pack 8 bits per byte
+*/
+char graphics[X_SIZE / 8][Y_SIZE]; // the graphics data
+
+/****************************************
+* set_bit -- set a bit in the graphics *
+* array *
+* Parameters *
+* x,y -- location of the bit *
+****************************************/
+inline void set_bit(const int x, const int y){
+ assert((x >= 0) && (x < X_SIZE));
+ assert((y >= 0) && (y < Y_SIZE));
+ graphics[(x)/8][y] |= static_cast<char>(0x80 >>((x)%8));
+}
+
+/****************************************
+* clear_bit -- clear a bit in the *
+* graphics array *
+* Parameters *
+* x,y -- location of the bit *
+****************************************/
+inline void clear_bit(const int x, const int y){
+ assert((x >= 0) && (x < X_SIZE));
+ assert((y >= 0) && (y < Y_SIZE));
+ graphics[(x)/8][y] &= static_cast<char>(~(0x80 >>((x)%8)));
+}
+
+/****************************************
+* test_bit -- test whether a bit in the *
+* graphics array is on or off *
+* Parameters *
+* x,y -- location of the bit *
+* Returns *
+* whether the bit is a 1 or 0 *
+****************************************/
+inline bool test_bit(const int x, const int y){
+ assert((x >= 0) && (x < X_SIZE));
+ assert((y >= 0) && (y < Y_SIZE));
+ return (graphics[(x)/8][y] & (0x80 >>((x)%8))) != 0;
+}
+
+int main() {
+ int loc; // current location to print
+ void print_graphics(); // print the graphics data
+
+ // draw a diagonal line across the screen
+ for (loc = 0; loc < X_SIZE; loc++)
+ set_bit(loc, loc);
+
+ clear_bit(loc-1, loc-1);
+ bool is_set1 = test_bit(loc-2, loc-2);
+ bool is_set2 = test_bit(loc-1, loc-1);
+
+ // print graphics data
+ print_graphics();
+
+ std::cout << is_set1 << "\n";
+ std::cout << is_set2 << "\n";
+
+ return(0);
+}
+
+/****************************************
+* print_graphics -- print the graphics *
+* bit array as a set of X and .'s *
+****************************************/
+void print_graphics(){
+ int x; // current x BYTE
+ int y; // current y location
+ int bit; // bit we are testing in the current byte
+
+ for (y = 0; y < Y_SIZE; y++) {
+ // loop for each byte in array
+ for (x = 0; x < X_SIZE / 8; x++) {
+ // handle each bit
+ for (bit = 0x80; bit > 0; bit = (bit >> 1)) {
+ assert((x >= 0) && (x < X_SIZE / 8));
+ assert((y >= 0) && (y < Y_SIZE));
+
+ if ((graphics[x][y] & bit) != 0)
+ std::cout << 'X';
+ else
+ std::cout << '.';
+ }
+ }
+ std::cout << '\n';
+ }
+}
A 11/graph/graph.md => 11/graph/graph.md +30 -0
@@ 0,0 1,30 @@
+# graph
+
+> Bitmapped graphics engine
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+A program to control a bitmapped pixel display. Implements functions to
+set, clear, and test pixels on the display. Also implements a dummy
+display for testing purposes.
+
+## Example
+
+> X...............
+> .X..............
+> ..X.............
+> ...X............
+> ....X...........
+> .....X..........
+> ......X.........
+> .......X........
+> ........X.......
+> .........X......
+> ..........X.....
+> ...........X....
+> ............X...
+> .............X..
+> ..............X.
+> ................
+> 1
+> 0
A 11/split-int/Makefile => 11/split-int/Makefile +13 -0
@@ 0,0 1,13 @@
+# Makefile for progam split-int
+
+# Turn on debugging
+CXXFLAGS = -g
+
+split-int:split-int.cpp
+ $(CXX) $(CXXFLAGS) $^ -o $@
+
+clean:split-int
+ rm $^
+
+run:split-int
+ ./$^
A 11/split-int/split-int.cpp => 11/split-int/split-int.cpp +64 -0
@@ 0,0 1,64 @@
+/****************************************
+* split-int -- splits a int in to eight *
+* 4-bit values *
+* Usage: Input an integer at the prompt *
+****************************************/
+
+#include <iostream>
+
+/****************************************
+* split_integer -- split int into *
+* eight 4-bit values *
+* Parameters *
+* integer -- integer to convert *
+* Returns *
+* integer array of split values *
+****************************************/
+void split_integer(const int integer, short int split_ints[]){
+ for (int i = 0; i < 8; i++) {
+ split_ints[i] = (integer >> (4 * i)) & 0xF; // Right shift and bitwise AND operation
+ }
+}
+
+/****************************************
+* print_bits -- print all bits in an *
+* integer *
+* Parameters *
+* integer -- integer to print *
+****************************************/
+void print_bits(int integer) {
+ for (int i = 0; i < sizeof(integer) * 32; i++) {
+ std::cout << ((integer >> i) & 1);
+ }
+}
+
+int main() {
+ int integer; // integer to test
+ short int split_ints[8]; // array to store split values
+
+ // get user input
+ std::cout << "Enter an integer: ";
+ std::cin >> integer;
+
+ // print bits of input integer
+ print_bits(integer);
+ std::cout << "\n";
+
+ // split the integer
+ split_integer(integer, split_ints);
+
+ // print bits of split values
+ for(int i = 0; i < 8; i++) {
+ print_bits(split_ints[i]);
+ std::cout << "\n";
+ }
+
+ // print split values as decimal
+ for(int i = 0; i < 8; i++){
+ std::cout << split_ints[i] << " ";
+ }
+ std::cout << "\n";
+
+ return(0);
+}
+
A 11/split-int/split-int.md => 11/split-int/split-int.md +22 -0
@@ 0,0 1,22 @@
+# split-int
+
+> Splits an integer into eight 4-bit values
+> Users' Specification
+> Jan 27, 2023 Bobby Hamblin
+
+Given an integer composed of 32 bits, this program splits it into
+eight 4-bit values. Values are supplied as both binary and decimal.
+
+## Example
+
+> Enter an integer: *-123456789*
+> 11010111010011000010010100011111110101110100110000100101000111111101011101001100001001010001111111010111010011000010010100011111
+> 11010000000000000000000000000000110100000000000000000000000000001101000000000000000000000000000011010000000000000000000000000000
+> 01110000000000000000000000000000011100000000000000000000000000000111000000000000000000000000000001110000000000000000000000000000
+> 01000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000001000000000000000000000000000000
+> 11000000000000000000000000000000110000000000000000000000000000001100000000000000000000000000000011000000000000000000000000000000
+> 00100000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000000100000000000000000000000000000
+> 01010000000000000000000000000000010100000000000000000000000000000101000000000000000000000000000001010000000000000000000000000000
+> 00010000000000000000000000000000000100000000000000000000000000000001000000000000000000000000000000010000000000000000000000000000
+> 11110000000000000000000000000000111100000000000000000000000000001111000000000000000000000000000011110000000000000000000000000000
+> 11 14 2 3 4 10 8 15
A 12/mailing-list/mailing-list.md => 12/mailing-list/mailing-list.md +3 -0
@@ 0,0 1,3 @@
+# mailing-list
+
+