S
scooby.doo
Hi,
I need to turn certain bits in a 8-bit word on depending on a decimal
value. For example if the decimal value is 1, turn the first bit on.
Decimal = 5 turn the first 5 bits on, and so on. Now I don't know the
correct terminology for what I'm trying to do, so that hasn't helped
me looking in reference manuals or the Internet. The only way I can
see of doing it is:-
unsigned char values[7] = {1, 3, 7, 15, 31, 63, 127};
main ()
{
unsigned char i;
for (i = 0; i < 8; i++) use_byte(values);
}
I do not need to worry about the last bit as if the byte is full (i.e.
decimal 8) that is handled differently.
Is this a sensible solution?
Thank-you.
I need to turn certain bits in a 8-bit word on depending on a decimal
value. For example if the decimal value is 1, turn the first bit on.
Decimal = 5 turn the first 5 bits on, and so on. Now I don't know the
correct terminology for what I'm trying to do, so that hasn't helped
me looking in reference manuals or the Internet. The only way I can
see of doing it is:-
unsigned char values[7] = {1, 3, 7, 15, 31, 63, 127};
main ()
{
unsigned char i;
for (i = 0; i < 8; i++) use_byte(values);
}
I do not need to worry about the last bit as if the byte is full (i.e.
decimal 8) that is handled differently.
Is this a sensible solution?
Thank-you.