David Lazar on his open source base64 encoding:

The C code in base64encode.c is a fast implementation of Base64 encoding. It is based on libb64, which uses coroutines to achieve speed. The nontrivial control-flow of this code makes proving it correct more challenging.

The writeup includes background information on “the proof” verifying the C implementation.

The code is available on github.

One of the wonderful(?) things about Objective-C is that it’s based on C. Part of the power of C is bit-bashing, where you can manipulate individual bits inside of a piece of memory…That being said, there are times where bitwise operations appear in the Cocoa APIs, so it’s good to be comfortable with a couple of basic operations.

With that intro, Mark Dalrymple of Big Nerd Ranch covers the basics of working with bits and the related operators.

Given space is often at a premium when writing applications for mobile devices, I want to show you how to use bitfields to manage a series of values that need only on/off status. The upside is that you can store a surprising number of status values within a single integer, 32 to be exact.

The code that follows is pure C. Given that Objective-C is a superset of C, don’t forget that you can leverage all that C has to offer, beyond working with objects.

Read more »

If you ever come upon a need to toggle an integer value between 1 and 0, consider using the bitwise exclusive-OR (^) operator in C to get the job done.

In a recent application I wrote a method with one parameter, an integer, that is expected to be 1 or 0. In creating a demo of the application I wanted to pass in alternating values of 1 and 0 as part of a test for a specific use case. Instead of using an if statement in the calling method to decide when to send a 1 or 0, I wrote something similar to the code below:
Read more »