     let ptr = UnsafePointer<UInt8>(hash.bytes)
     let offset = ptr[hash.length-1] & 0x0f
 
-    // Take 4 bytes from the hash, starting at the given offset
+    // Take 4 bytes from the hash, starting at the given byte offset
     var truncatedHashPtr = ptr
     for var i: UInt8 = 0; i < offset; i++ {
         truncatedHashPtr = truncatedHashPtr.successor()

    }

    // Ensure the counter value is big-endian
    // TODO: use CFSwapInt64HostToBig instead
    var bigCounter = _OSSwapInt64(counter)

    // Generate an HMAC value from the key and counter
    let (hashAlgorithm, hashLength) = hashInfoForAlgorithm(algorithm)

    var truncatedHash = UnsafePointer<UInt32>(truncatedHashPtr).memory

    // Ensure the four bytes taken from the hash match the current endian format
    truncatedHash = UInt32(bigEndian: truncatedHash)
    // Discard the most significant bit
    truncatedHash &= 0x7fffffff
    // Constrain to the right number of digits
    truncatedHash = truncatedHash % UInt32(pow(10, Float(digits)))

    var string = String(truncatedHash)
    // Pad the string representation with zeros, if necessary
    while countElements(string) < digits {
        string = "0" + string
    }
