In my first semester of college I made an algorithm to avoid wasting memory, just for testing.
Now I'm passing this code to C:
Here is the whole code:
// 8 bits
// Aguenta até 4 slots (0 - 3)
// Valor inteiro máximo suportado: 255
void setBit8(int *pInt32, int index, int valor)
{
*pInt32 = (*pInt32 & ~(0xff << index * 8)) ^ (valor << (index * 8));
}
int getBit8(int *pInt32, int index)
{
return ((*pInt32 >> (index * 8)) & (0xff >> 32));
}
// exemplo de uso:
setBit8(&var, 2, 168);
printf("%d", getBit8(&var, 2)); // imprime 168;
And I get the following warning in the getBit8
function:
warning: right shift count >= width of type
The intention is to make the same 4-byte variable can receive up to 4 integer values inside it, being able to access or modify these values, such as an array ...
What is the problem / error?