Math is weird and is sometimes frustrating, but it can certainly be beautiful.

The Bit Order Shuffle. For an explanation, keep reading...

The Bit Order Shuffle. (For an explanation, keep reading.) Click for uncompressed BMP.


When I first took a Digital Electronics course years ago, the instructor started talking about what sounded like “big-Indian” and “little-Indian” formats. I wasn’t really sure what he was talking about — but then I read the textbook. (It’s actually useful, on occasion, provided that the instructor isn’t the author.)  As it turns out, there are two main ways of storing binary numbers — with the “big end” first, or the “little end” first. Thus, “Big-Endian” and “Little-Endian.” Endian-ness, not “Indian-ness.”


This can’t be what the professor meant, right? (Drawing by Millard E. Carr)


In Big-Endian format, the largest bits (and bytes) of a binary number are stored first. So, the number 0100 would represent “four,” and the number 10100000 would represent “one hundred sixty.” Motorola processors (Freescale, these days) are big-endian.

In Little-Endian format, the order is reversed: the smallest bits come first. So, 0100 would represent “two,” and 10100000 would represent “five.” Intel CPUs are little-endian.

Both systems are well entrenched (although I confess I don’t understand why someone would use little-endian when most networks use big-endian), so it’s important to know about the problem of endianness, and how to convert between the two (using LIFO buffers, if dealing with serial data.)

But back to the “Bit Order Shuffle” image, above. It turns out that when you read the numbers in backwards order like this, you shuffle the value order of the numbers. 0000 will still be first in a list of four-bit numbers and 1111 will still be last — but 0001 will become 1000, jumping to the middle of the deck — and 0011 (three) will become 1100 (twelve) etc.

I decided to visualize this, and colored the numbers 0-1023 with a continuous color spectrum in the 24-bit RRGGBB space, with Red mapped to 255-(n/8), Green mapped to 255-abs(512-n)/4, and Blue mapped to n/8. (All values clamped 0-255.) In order to try to avoid the pattern being dominated by the last lines to be drawn rather than the overall pattern, the lines are drawn in random order, with the law of averages ensuring most or all lines were drawn.

As the pattern shows, an initially well-ordered set is shuffled — repeatably and reversibly — into a homogenous mix of values. It would be a good shuffle, if it wasn’t ultimately predictable.

As for my Dad’s “Indians” — they’ve found work as corporate bit-order spokespeople.


Posted in Digital, Math, Networking | Leave a comment

Gotta catch ’em all!

A few days ago, Niantic (of Ingress fame vague familiarity) unleashed Pokémon Go on the world.

If you’ve been living on a rock for the past week, Pokémon Go is the latest phase of the popular Japanese Pokémon (“Pocket Monsters”) franchise, which has been around since the late 1990s. The twist with this latest version, though, is that it uses real-world places as the playing field for the game. Players walk around their neighborhoods, searching for virtual Pokémon that the game superimposes on the real world.

Ran across this guy (turned out to be something called a Grimer) on campus. There are some weird ones out there!

Ran across this guy (turned out to be something called a Grimer) on campus. There are some weird ones out there!

It’s perhaps the first truly popular Augmented Reality (AR) game — and judging from the overwhelmingly positive response, it’s leading the way to a whole new genre of gaming that has the potential to completely reshape what we think of gaming.

Like any nascent paradigm shift, though, Pokémon Go and similar AR games are not without their potential hazards. Here are my thoughts — on the good and bad — after an evening or so playing Pokémon Go.

It gets geeks like me out and about
This is probably the biggest point in the game’s favor. You progress in the game largely by walking around. Whereas more traditional games like Skyrim have sometimes been criticized as “walking simulators,” there’s nothing simulated about the walking Pokémon trainers are doing, tracking down that elusive, rare … seventeenth Ratatta in a row.

It teaches you local geography and history
Pokéstops — important nodes in the game where you can obtain items for free — correspond to points of interest on Google Maps. It’s unclear exactly how these points were chosen, but churches seem to be favorite slots, as do many of Philadelphia’s murals. I’ve learned perhaps half a dozen interesting things about Mantua, Powelton Village, and West Philadelphia in general just by playing.

…as long as you watch where you’re going
I strongly recommend playing in a safe area. Many people have commented how college campuses are awesome places to play. Presumably they were talking about the proximity of so many players (with lures, etc) to points of interest. However, another good reason to play on campus is because of the security. If you’re walking around, keeping out of traffic, and trying to find that Pikachu that someone said was over on this side of town, you’re probably not as aware of all of the people around you as you should be — and not all people are to be trusted. It’s important not to become a smartphone zombie. Stick your head outside your digital bubble and look around once in a while. Watch your six.

…and if the servers aren’t on fire.
I feel sorry for whomever Niantic contracted to for their data services. Because from the look of things client-side, their data centers are probably about to melt through the floor. Quite a few of the people I saw outside — possibly as many as 10-20% — were also playing. There’s no question it’s very popular. So much so, that people have set up websites tracking whether the servers are currently up or down.

Some of the dynamics raise security concerns
Players walk around in the real world while playing. They are free to go wherever they choose — but obviously, some directions are going to have more points of interest than others. It’s also possible to track down Pokémon in your area by looking for “rustling leaves” on the screen.

So these Pokémon — as well as points of interest — are influencing where people are going, perhaps without the people being aware. (I found myself walking down a route I hadn’t taken before, and realized I was walking along Powelton Ave, when I usually just cross over it northbound.)

Businesses are already catching on to this, advertising that they are Pokéstops or perhaps offering discounts to customers who set up lure modules on the local node. Or they play and set up a node there, themselves, in order to draw customers who will sit and play as they eat.

There have also, of course, been reports of muggers setting up lures, hoping to draw victims to them. How apropos.

This could be an insanely effective way to crowdsource searching for something.
Pokémon Go is a dramatic example of the power that games have to get people to do things. (I mean, come on. I walked to work and back even though I was done working — from home — for the day.) Imagine what such a game could do, if people were scored on types of wildlife they photographed, or number of potholes they reported, and so on. Crowds of people could be out there, looking for actual useful data instead of pocket monsters.

Pokémon Go is one of the more thought-provoking games I’ve come across. Ingress, also by Niantic, was another — but they’ve done a much better job with implementation this time.

A few tweaks — some major, some minor — would greatly help the experience, though:

  • Maybe perhaps buy a second server. Just sayin’.
  • Instructional videos on what constitutes a good Pokéball toss would be very helpful. A lot is lost in the 2D-3D transition.
  • Why all the emphasis on fighting? People are getting in real-life fights over this. I’m having fun just collecting the little critters.
  • The Pokémon transfer mechanism needs to be speeded up. Let us look at all of the stats of the Pokémon we’ve captured, and check which ones we want to transfer, rather than having to dig through each slow-loading screen individually and then scroll down past the map which loads halfway there, slowing things down.

I would consider the game to be mid-to-late beta at this point, mostly because the servers are not yet up to handling the game’s unexpected runaway popularity. It’s still a lot of fun to play as long as you watch what you’re doing. And it’s certainly a harbinger of a whole genre of interesting AR games to come.

Go Team Mystic!

Posted in Current Events, Digital, Digital Citizenship, Games, Internet, Reviews, Toys | Leave a comment

Apollo 11 source code made public

NASA has just released the source code used for the Apollo 11 lunar landing mission.

You know — the code in the stack of printouts Margaret Hamilton is showing off in that famous NASA picture.

Apollo Guidance Computer project lead Margaret Hamilton shows off the printouts of the AGC software.

Apollo Guidance Computer project lead Margaret Hamilton shows off the printouts of the AGC software.

Anyway, it’s up on github. It may be a bit more difficult than most libraries to re-use, being written in AGC4 assembly language — but it’s an important piece of technological history.


Posted in Assembly, Aviation, Coding, Current Events, Design, Digital, Digital Citizenship, Nostalgia | Leave a comment

The Calibration Equation

One of the most important Engineering concepts is that of the closed loop. In order to improve something, you need the ability to change it in appropriate ways — as well as the ability to know whether these changes are making the end result better or worse. Specifically, you need to measure it and determine the amount of error.

The classic example of this is a thermostat. A thermostat connected to a heater might, for example, be set to keep a room at around 20 degrees C. If the room gets significantly warmer than this, no more heat is needed, and the thermostat can shut off the heater. If it gets too cold, heat is needed, and the thermostat turns the heater back on.

This principle is more widely useful than just for home heating controls, however. The same principle, with a few adjustments, can be used for calibration of systems — or measurements.

I recently upgraded the Z axis motion on my 3D printer, which should result in much smoother (and efficient) motion. It’s already resulted in better-looking parts. However, the 8mm lead screws that were suitable had a much different pitch than the threaded rod the old Z-axis design had used. Since 3D printers operate by counting how far they’ve gone, not compensating for this would result in far too much distance between layers. The firmware would rotate the steppers by the same too-large amount, not knowing that the effective mechanical steps-per-mm had been greatly reduced.

The wrong steps-per-mm setting for the Z axis can produce a complete bird's nest.

The wrong steps-per-mm setting for the Z axis can produce a complete bird’s nest.

Clearly, the 2550 steps/mm Z axis setting had to be reduced. But by how much? As it turns out, since the relationship here is linear, there’s a handy equation you can use to estimate the correct number.


This is, ideally, an iterative process. P(n) represents the latest estimate of the correct calibration constant; it is calculated by taking the current calibration constant — P(n-1), and multiplying it by D (Desired), divided by O (Obtained.)

So, multiply the current setting by what you want, divide it by what you got, and the result should be fairly close to accurate. One or two iterations of this process should reduce any remaining error to well under a percent, in most situations.

In the case of the 3D printer, the initial setting was 2550 steps per mm. With this setting, a commanded z-axis movement of 10mm actually resulted in a movement of 61.3mm. Using this result, I reset the setting to about 416 and tried again. Eventually, iterating this process, I ended up with a Z-axis setting of 402.4 — not too far off the initial estimate.

The disclaimer, of course, is that this may not work in situations where the calibration curve isn’t constant — that is, where the relationship between the input and output of the system is nonlinear. But that’s a Calculus discussion, and one for another day.

Posted in 3D Printing, HOW-TO, Math, Science, Troubleshooting | Leave a comment