Lab 13: Braille Translator -- 4/28/2020

COSC 2200, Spring 2020

Marquette University, Department of Computer Science

Description

In our final lab, you will make use of the given Braille Table array to handle simple cases.

  1. If you have not yet done so, get a fresh copy of the updated pi3Playground which includes the HW9 template file that you need.
    tar xvzf ~pmcgee6/cosc2200/pi3Playground.tgz
  2. Solve the problem. Show a demo to the TA when finished.

TODO: Simple Braille Translator

Note: It is good practice to use helper routines when writing code that often performs checks (e.g. character checking), especially when printing output based on such checks.

There are two fundamental elements of this assignment: 1) Using the lookup table to determine whether to print a raised dot, and 2) Printing correctly (row-by-row). As stated in class, there are six possible positions for printing (a 3x2 grid). To determine whether to print a '@' or a '.', we can use the brailleTable and bitwise operations. In this lab, you will write braille translator that can translate lowercase letters and numbers. When complete, your low-detail implementation should serve as a good starting point for solving the rest of the assignment.

To begin, first design a simple printing structure to print row-by-row. For instance, you may have used a nested for loop in the last "grid printer" lab to accomplish this. Next is the trickier part. We know there are three rows of two elements. Since we are printing row-by-row, we need to print the top row first (positions 0 and 3), then the second row (positions 1 and 4), and then the last row (positions 2 and 5). If we are printing the first (top) row, we need to determine whether those two dots (if any) are raised. This lab is only asking for the simple cases of characters that are lowercase or digits. If the ASCII character is lowercase, then we can perform a lookup in the brailleTable at index c-'a'. Save this lookup character, and perform bitwise operations to determine whether to print a raised dot.

Let's say the character d is in question. A lookup would return hex value 0x19, which is equivalent to 00011001 in binary. Let's assume we are printing the first row (positions 0 and 3). Use the following bitwise operation to keep the least significant bit, which (thanks to the given table) will be used to determine whether there is a raised dot.

(0x19 >> 0) & 1

Where the lefthand side of the right bitshift operator is the lookup character supplied by the table, and the righthand side is the position we are currently on (0 is the top-left position of the grid). 00011001 >> 0 = 00011001 (since we are shifting the number rightward by zero bits, our value is unchanged). 00011001 & 00000001 = 00000001 (equivalent to 1; raised dot is printed).

Of course, just to complete printing of the top row, we need to perform this operation a second time to determine whether the second position in the first row (upper-right position) is a raised dot. Thus, with the character d still in question, the operation for the upper-right position would look like: (0x19 >> 3) & 1. 00011001 >> 3 bits = 00000011. Since the rightmost bit is 1 (determined by AND (&) operation), then this is a rasied dot as well.