I am trying to understand this C code which is supposed to take an integer input value and convert it to a binary number for encryption purposes. For some reason, a static int is declared without initialization and then on the subsequent line it is checked to see it is divisible by 32? The X2 variable is an integer array with a length of 32 that gets modified by this function. Why is the divisibility check done on an uninitialized static int? And what if it is not divisible by 32? It might a billion and if it is not divisible by 32, the function would use it as an index into an array that has a length of 32, which would cause the program to crash. And then at the end i is incremented by 4? Why 4? This function is not making any sense to me. Does this code make sense to anybody?
int ToBits(int value)
{
int k, j, m;
static int i;
if(i % 32 == 0)
i = 0;
for (j = 3; j >= 0; j--)
{
m = 1 << j;
k = value & m;
if(k == 0)
X2[3 - j + i] = '0' - 48;
else
X2[3 - j + i] = '1' - 48;
}
i = i + 4;
}