Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Part 1: One Character Create a program that prints one character, similar to the above example. Your program must Use loops to generate the 8x8
Part 1: One Character Create a program that prints one character, similar to the above example. Your program must Use loops to generate the 8x8 pattern o At least one loop for the rows o At least one loop for the columns -Create the 8x8 pattern from an encoded number image" (e.g. 64-bit unsigned integer) o Use an "unsigned long int datatype for your 64-bit encoded number o Alternately use the-uit64-t" datatype. Be sure to add the line: # include o The encoded number can be hard-coded fi.e. a constant integer). It does not have to come from user input. Use "Ox in front of the number in your code to tell the compiler it's hexadecimal. HINT 1: In your row loop, you will need to extract 8 bits from the 64-bit number each time it loops. math operators or use bitwise operators to isolate the proper 8 bits out of the 64 for that row Use HINT 2: In your column loop, you will need to focus on just one bit of the 8-bit row number each time it loops. Use math or bitwise operators to mask or isolate the bit that corresponds to the column the loop is currently printing. Example Image Print Algorithm Consider the 64-bit image 0x10387cfe38383800: Loop 1 (start at row 0, byte 0): Isolate the Lowest byte: 10387cfe383838 00 (byte 0) Loop 2: (start at Column 0, bit 7): Isolate the highest bit 0 000 0000 (bit 7) Is it a zero? Print a space Is it a one? Print an asterisk. Repeat for columns 1-7 using bits 6-0) (Repeat for rows 1-7 using bytes 1-7) To test your code, try the following encoded integers: -0x1018fcfefc181000 - 10387cfe38383800 Part 2: Implement a Complete Font Modify your code from Part 1 such that it can print any letter (upper or lowercase) that the user enters. Your code will print the letter as a star pattern on the console. Example1 Enter a letter: A The star pattern image for 'A' is Coding Help: Fonts 8x8 matrix fonts are available on the Internet. Here is an example website: The matrix in the middle of the screen is the 8x8 dot/star pattern. You can click on the matrix to create your own character or icon. The code on the right side of the screen under "Arduino /C Code" is the variable declaration and initialization statement you would paste into your code. At the left side of the screen are complete fonts. There are three font sets to choose from. Click on letters' from any of the font sets. Now, on the right side of the screen, you should have an array declaration and initialization statement for the entire alphabet, including upper and lower cases. Paste the code into your main() function. You may need # include at the top of your program. Info: stdint.h is a set of variable definitions you can use to ensure that you get an integer of a specific size. (Recall the byte sizes of the named ints are not all guaranteed from one machine type to another.) uint64 means "unsigned integer 64 bits On most machines, you could likely get the same type using: unsigned long int Now that you have the font loaded as an array of uint64's, you can get the code for any letter by using an index on the array. Looking at the website from earlier, you can see that the upper case letters come first followed by the lowercase letters, in alphabetical order. Therefore, the index for 'A' is 0 (the first symbol in the array), and the index for 'a' is 26 (the next symbol after Z). Uppercase letters indices are 0-25. Lowercase letters are indices 26-51. Example 2 (Your Code) Here is some example code you could use to get the correct symbol from your font array First, you need a variable to store the chosen symbol's font uint64 t currentSynbol: unsigned char userInput: int imageIndex; if (isUpper (userInput)) // storage for the current image // stores what the user types // index of the current image image Index = userInput- "A,; // use this for uppercase ) else I imageIndexuserInputa II use for lowercase currentSymbol IMAGES [image Index); // number in brackets selects the image = You will need to include code to ask the user to input a letter. You will also need code to check whether the input is valid (is a character). If the input is not valid, your program should ask the user to try again using a loop to get back around to the user input code. Consult the textbook and/or online sources if you need help with arrays. Once you have this working properly, you can pass currentSymbol to your matrix printing routine you created in Part 1. Code Begin writing valid C statements to match exactly what the pseudo-code describes. Don't delete your pseudo-code. It should remain in your code as helpful commentary for others to follow your intentions (and for you to remember what your code is supposed to do). Loops: Make your program count Nearly every program needs to count somewhere in the algorithm. A counter can keep track of items (e.g. number of times the word "code" appears in this document), or more often it is simply counting how many time s a loop has looped. For example: //METHOD 1: USING A FORO LOOP int x: //declare the variable to do the counting //start at zero, keep doing the following as long as x is less than 10, increment x each time through for (x=0; x o The encoded number can be hard-coded fi.e. a constant integer). It does not have to come from user input. Use "Ox in front of the number in your code to tell the compiler it's hexadecimal. HINT 1: In your row loop, you will need to extract 8 bits from the 64-bit number each time it loops. math operators or use bitwise operators to isolate the proper 8 bits out of the 64 for that row Use HINT 2: In your column loop, you will need to focus on just one bit of the 8-bit row number each time it loops. Use math or bitwise operators to mask or isolate the bit that corresponds to the column the loop is currently printing. Example Image Print Algorithm Consider the 64-bit image 0x10387cfe38383800: Loop 1 (start at row 0, byte 0): Isolate the Lowest byte: 10387cfe383838 00 (byte 0) Loop 2: (start at Column 0, bit 7): Isolate the highest bit 0 000 0000 (bit 7) Is it a zero? Print a space Is it a one? Print an asterisk. Repeat for columns 1-7 using bits 6-0) (Repeat for rows 1-7 using bytes 1-7) To test your code, try the following encoded integers: -0x1018fcfefc181000 - 10387cfe38383800 Part 2: Implement a Complete Font Modify your code from Part 1 such that it can print any letter (upper or lowercase) that the user enters. Your code will print the letter as a star pattern on the console. Example1 Enter a letter: A The star pattern image for 'A' is Coding Help: Fonts 8x8 matrix fonts are available on the Internet. Here is an example website: The matrix in the middle of the screen is the 8x8 dot/star pattern. You can click on the matrix to create your own character or icon. The code on the right side of the screen under "Arduino /C Code" is the variable declaration and initialization statement you would paste into your code. At the left side of the screen are complete fonts. There are three font sets to choose from. Click on letters' from any of the font sets. Now, on the right side of the screen, you should have an array declaration and initialization statement for the entire alphabet, including upper and lower cases. Paste the code into your main() function. You may need # include at the top of your program. Info: stdint.h is a set of variable definitions you can use to ensure that you get an integer of a specific size. (Recall the byte sizes of the named ints are not all guaranteed from one machine type to another.) uint64 means "unsigned integer 64 bits On most machines, you could likely get the same type using: unsigned long int Now that you have the font loaded as an array of uint64's, you can get the code for any letter by using an index on the array. Looking at the website from earlier, you can see that the upper case letters come first followed by the lowercase letters, in alphabetical order. Therefore, the index for 'A' is 0 (the first symbol in the array), and the index for 'a' is 26 (the next symbol after Z). Uppercase letters indices are 0-25. Lowercase letters are indices 26-51. Example 2 (Your Code) Here is some example code you could use to get the correct symbol from your font array First, you need a variable to store the chosen symbol's font uint64 t currentSynbol: unsigned char userInput: int imageIndex; if (isUpper (userInput)) // storage for the current image // stores what the user types // index of the current image image Index = userInput- "A,; // use this for uppercase ) else I imageIndexuserInputa II use for lowercase currentSymbol IMAGES [image Index); // number in brackets selects the image = You will need to include code to ask the user to input a letter. You will also need code to check whether the input is valid (is a character). If the input is not valid, your program should ask the user to try again using a loop to get back around to the user input code. Consult the textbook and/or online sources if you need help with arrays. Once you have this working properly, you can pass currentSymbol to your matrix printing routine you created in Part 1. Code Begin writing valid C statements to match exactly what the pseudo-code describes. Don't delete your pseudo-code. It should remain in your code as helpful commentary for others to follow your intentions (and for you to remember what your code is supposed to do). Loops: Make your program count Nearly every program needs to count somewhere in the algorithm. A counter can keep track of items (e.g. number of times the word "code" appears in this document), or more often it is simply counting how many time s a loop has looped. For example: //METHOD 1: USING A FORO LOOP int x: //declare the variable to do the counting //start at zero, keep doing the following as long as x is less than 10, increment x each time through for (x=0; x
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started