How to recover the Borrow Bit

In a similar way as the carry bit for addition it is possible to recover the borrow bit for substraction, just based on the highest bits of three numbers that we deal with during the operation. With this program, a subtraction operation of an 8-bit CPU can be simulated exhaustively #!/usr/bin/perl my $x, $x, $bi; my %tab = (); for ($bi = 0; $bi  7;             my $zs = $z >> 7; …

Share Button

Exceptions to implement Program Logic

Sometimes it is conveniant to use exceptions for implementing the regular program logic. Assuming we want to find some data and then process them. When no data is found, this step can be skipped, because there is nothing to do. So we could program something like this: public Data readData(Param param) {     Data data = db.read(param);     if (data.isEmpty()) {         throw new NotFoundException(„nothing found“);     }     return data; } public ProcessedData doWork(Param param) { …

Share Button

How to use $ in Articles using WP QuickLaTeX

I use WP QuickLaTeX by Pavel Holoborodko in some of my articles to include mathematical formulas. Now it can be an issue that the „$“-sign, that marks the beginning of a formula, is used as dollar sign. This can be achieved by using [latexpage] in the beginning of the page. Sometimes it is desirable, to …

Share Button

Borrow and Carry Bit for Subtraction

Similar to the usage of the carry bit when adding there are mechanisms for subtracting that allow to integrate the result of subtraction of the lower bits into the subtraction of the next higher block of bits, where necessary. There are two ways to do this, that are trivially equivalent by a simple not operation: …

Share Button

Poor mans profiling with LOGs

We have professional profiling tools and we should use them.. They give really useful and extensive information. So why bother about doing „poor man’s profiling“? About ten years ago, running profilers was kind of constrained to very small examples and computers with really huge memory. We have this huge memory now on every development machine. …

Share Button

Rounding to Rational Numbers

Usually we think of rounding as a way of approximately expressing numbers with many decimal places by numbers with fewer decimal places. Regular readers of this blog have already encountered, that this concept can be extended and generalized, as is mentioned in the article about Geometric and Harmonic Rounding and Residue Class Rounding or Rounding …

Share Button

Accident Languages

Some commonly used languages have been quite well designed or at least would have been considered so at the time when they appeared. Even if they have their weaknesses, they should be good for some purposes. Now beauty of programming languages is highly subjective. So I do not claim any universal truth to this. But …

Share Button

UUIDs revisited

UUIDs have proven useful in many circumstances. We have basically two main variants: The UUID is calculated as a combination of the Ethernet-MAC-address, the timestamp and a counter. The UUID is calculated using a good random number generator While variant 1 provides for a good uniqueness, there are some issues with it. Today we use …

Share Button

How to calculate Square Roots and Cubic Roots

The functions sqrt and sometimes even cbrt are commonly available, but it is nice to see how they can be calculated. There are several approaches, but the most popular ones are Newton’s method and an algorithmic formulation of how roots are taken manually, for those old enough to still have learned it in school. Earlier …

Share Button

Guava-Collections in Java-APIs

When we write APIs, that have parameters or as return values, it is a good idea to consider relying on immutable objects only. This applies also when collections are involved directly or indirectly as content of the classes that occur as return values or parameters. Changing what is given through the API in either direction …

Share Button