[code]
1 << i;
makes the values:
00000001
00000010
00000100
00001000
00010000
00100000
01000000
10000000
assuming that it runs 8 times. Then by using a bitwise OR on each one, the one's just add together. So
00000001
00000010
00000100
00001000
00010000
all OR'd together makes
00011111
if you want to make the output look like
11110000
for an input of 4, then you could do this:
for(byte i = 0; i < temp; i++)
{
b = b | (1 << (8-i));
}
That makes it go in reverse order.
I'm almost certain there is a better way to do this than using a loop or a lookup table though.[/code]