Bitwise operations are often involved in algorithms, and these bitwise operations require fixed-width integers, such as the following example:
void Tea(uint32_t* v, uint32_t* k) { uint32_t v0 = v[0], v1 = v[1], sum = 0, i; /* set up */ uint32_t delta = 0x9e3779b9; /* a key schedule constant */ uint32_t k0 = k[0], k1 = k[1], k2 = k[2], k3 = k[3]; /* cache key */ for (i=0; i < 32; i++) { /* basic cycle start */ sum += delta; v0 += ((v1 << 4) + k0) ^ (v1 + sum) ^ ((v1 >> 5) + k1); v1 += ((v0 << 4) + k2) ^ (v0 + sum) ^ ((v0 >> 5) + k3); } /* end cycle */ v[0] = v0; v[1] = v1; cout << v0 << endl; cout << v1 << endl;}
This is a C language implementation of the tea algorithm. We need the unitn32_t type.
However, newlisp generally only has one Integer type, and its value range is-9,223,372,036,854,775,808 and + 9,223,372,036,854,775,807.
This is a 64-bit signed integer. So how can we limit the integer to uint32_t?
I wrote a function:
(define (u4 v) (first (unpack "lu" (pack "lu" v))))
Use pack to convert the integer V to the uint32 string, and then use unpack to convert the string to the uint32 integer.