Xor Swap

Introduction

Recently I came over this old school xor swap trick. It’s a trick that impressed me when I was a young coder and one of my friends first showed it to me. As I’ve grown older and with more understanding of computer architecture I use this trick as an example of how more complex solution does not really imply better. And in the fact of the XOR swap trick it is one of the things that makes you feel good over a tricky implementation, but will hurt performance at the end of the day.

Dithering

Background

Some time ago, I got myself one of these black and white e-ink paper without any support for grayscale. I.e. per pixel on the e-ink, I could only have either black or white, and no scale between. This kind of worked fine for true type font rendering, but I also wanted to be able to output images. And for that I had to be creative. Frame Now, there were a lot of specific problems related to the actual version of the e-ink screen that I got, but this post in particular is not going to focus on those. They might be covered in a future post if I get around to it. For now, this post is only going to cover dithering, and more specifically Floyd-Steinberg and algorithms derived from those.