Useless but fun

As you, my dear reader, may have already noticed from my previous posts, I am currently teaching a course on how computers work for first year students. Very high level, simplified stuff since there’s only ten hours of lectures and ten hours of exercises for this.

One course exercise is about logic gates. After the lectures on the topic, students use the Digital Logic Sim tool to design some simple logic gates. Starting from AND and NOT gates, they build a NAND (the universal) gate and then OR, NOR and XOR gates using these gates in the project of theirs.

Building an OR gate using three NAND gates.

After this, students design two gates handling a byte (eight bits). Logic gate (or chip) ISZERO, checking if a byte has a zero eight bit integer value. ISEVEN gate checks if a byte is an even number.

Finally, they combine these two gates to check if the value in the byte is an even number and greater than zero. In the end they will meet the question whether the byte is actually signed or unsigned. Since then they need to take into account if the most significant bit (msb) is zero or one. In a signed byte, the msb value of 1 means the value of the byte is actually a negative integer.

Anyhows, in one of the lectures I mention that:

Anything that can be implement in hardware, can also be implement in software. And anything that is implementable in software, can also be implemented in hardware.

So a thought popped in my head out of nowhere: “Should I implement a demonstration in C that actually does implement these gates in software, starting from the boolean operators && and !, not using the ones already in the language?”

Of course I had to do that. Useless and fun. Suits me just fine.

Logic gates AND and NOT are quite simple to implement using boolean operators of C:

bool and(bool x, bool y) {
	return x && y;
}

bool not(bool x) {
	return !x;
}

Then implementing the NAND gate using NOT and AND:

bool nand(bool x, bool y) {
	return not(and(x, y));
}

And the final example here, the OR operator implemented using three NANDS (compare this to the image of the OR gate above):

bool or(bool x, bool y) {
	return nand(nand(x, x), nand(y, y));
}

The rest you can find following the link above, including a demo app in gates.c and an output file from the app.

What I would like to change in the implementation is to have two implementations of the ISZERO gate, since signed and unsigned bytes should implement this gate differently.

But enough of these uselessnesses. For today, at least.

Automation of boring tasks

My ongoing 1st year introductory course on computers has Moodle exams containing different kinds of automatically graded questions like:

An arithmetic task containing radix conversions.

We need to use automatically graded exams since there is 250-300 students each year, too few teachers participating, so evaluating the exams manually would take forever and would be very boring task to do.

Perhaps a necessary disclaimer: Everyone knows these conversions and arithmetics are, in practice, done oftentimes using software tools (programmer’s calculators) or web sites, when you need to. The actual learning goal here is not to say to students that doing this manually is something you have to learn to do for this profession. The learning goal is to expose the way data and simple arithmetics is handled in a computer and play around with these things to get an understanding of how computers work. And in time, you learn to see, for example, when debugging, some things that might be important in the hex, octal or binary values in memory.

Having a large set of questions for a course topic is a good thing to have. Then each exam generated for a student has different set of questions, randomly chosen by Moodle.

This poses another boring task problem. I would have to write tens or hundreds of these questions, choosing the values to convert or calculate, converting them to different radices, calculate the result and then use Moodle question editor to write the questions. And translate them to Finnish (or from Finnish to English), since I teach the course in two languages.

Well, what do you need when you have simple, boring repetitive tasks to do…?

A computer.

Well, a computer alone is just a bunch of metal, sand and plastics, so in addition, software would be needed.

Since I enjoy programming much more than writing Moodle exam questions, I implemented a command line tool using Swift. This tool generates random number conversion tasks (decimal to hex to binary) and arithmetic tasks (summing different values in different radices). Then these tasks are saved in a Moodle XML exam question format in a file.

./ConversionQs output-fi.xml 20 fi --verbose

The command above generates 20 conversion and arithmetic tasks each, in Finnish, outputs them to output-fi.xml file and shows me the progress in terminal window (--verbose flag). Below is an excerpt from an English output file:

<?xml version="1.0" encoding="UTF-8"?>
<quiz>
    <question type="shortanswer">
        <name>
            <text>Convert between radixes</text>
        </name>
        <questiontext format="html">
            <text>&lt;p&gt;Convert the value 66 to radix: hexadecimal.&lt;/p&gt; 	&lt;p&gt;Consider the values to be signed bytes, with eight bits.&lt;/p&gt;
	&lt;p&gt;Write in the answer the prefix for the radix (0x, 0b) asked, if it is not decimal.&lt;/p&gt;
	&lt;p&gt;Otherwise, use only the digits of the requested numbering system, no spaces or other punctuations.&lt;/p&gt;</text>
        </questiontext>
        <defaultgrade>2.0000000</defaultgrade>
        <penalty>0.3333333</penalty>
        <answer fraction="100" format="moodle_auto_format">
            <text>0x42</text>
        </answer>
    </question>
 ...

Then I just import the XML file to Moodle, placing the questions into appropriate question category. Choosing a number of random questions from this set to an exam is an easy thing to do. Whenever I need a fresh set of questions, I just run the command again.

What a rise in productivity level of a teacher! Implementing this took around one working day. Now generating tens or even hundreds of exam questions happens in a fraction of a second, instead of hours and hours of mind consuming boredom!

Swift code exporting the generated questions to an XML file.

Teaching season launched, new apps

Yesterday was the first day of teaching in this Fall semester. Times are a bit challenging; teaching resources for the courses I teach in have shrinked down to about 58-66% of last year’s teaching hours, depending on a course. Also the number of teachers for a course is down. While number of students is going up rather than down.

Face-to-face teaching is not possible with these resources and number of students (225-300+ in two of the courses ongoing currently). We’d be in the classroom every day from 8am to 8pm and still have overlapping teaching events. So online it is. Hello Zoom.

One feedback item from students last year was that the terminology is challenging in the Devices and data network course. Understandable: in five two hour lectures I should be able to give an overview of how computers work and the components they contain. The same for the networking, ten hours of lectures and they should get a grasp on how the Internet and packet networks do their thing. This means a constant shower of new terminology unfamiliar to 1st year students. Other courses have similar issues.

So I developed a dictionary app for students to use. Or actually two. One with Java for desktop computers:

Dictionary Java app for desktop computers

And another one using Swift and SwiftUI for macOS, iOS and iPadOS:

The iPhone version of the dictionary app.

Both apps get the dictionaries from the same source, a remote git repository with a JSON file, using HTTPS. Thus the dictionaries can be edited, appended to and updates are then downloaded to the users’ devices.

In the user device the terms are stored into a SQLite database, so they can be used offline. Users can search for the terms and follow the URLs to sources in the Internet to find out more.

The desktop versions also have a feature that generates a graph of the relationships between the terms by searching the terms from other terms’ description. For this, GraphViz must be installed on the device.

The Swift version has a Widget for all Apple platforms. The widget randomly shows a couple of terms a day from the dictionary. Here’s the iPhone widget (along with the GitHub app widget on top):

And here is the macOS Widget:

Clicking or tapping on the term on the widget opens the app and shows the description as well as English term for that specific ICT term.

The Java version is already public and available for installation. Swift version is still under development, I just need to decide how to distribute it to the various types of devices and prepare the App Store information with screenshots, descriptions and all. Then there is the inevitable App Store review waiting. Hopefully it’ll pass. This is yet another app for the category “downloads and renders JSON in a GUI”.

Hopefully the students find the apps useful for learning. Next I should focus on finishing the dictionary for the basic Internetworking part of my course and put also that available for the apps to download…