| re: Set bits
Tim Hagan wrote:[color=blue]
>
> s wrote:[color=green]
> >
> > If I have:
> >
> > unsigned char value = 0xBD;
> > unsigned char 2bits = 0x02;[/color]
>
> 2bits is an invalid identifier. The first character must be a letter or
> an underscore, followed by any sequence of digits and/or upper or lower
> case letters.[/color]
I tried to paraphrase K&R2 (a *big* mistake) and flubbed it. I should
have mentioned that underscores are considered to be letters and can
appear anywhere in identifier names. However, it is not recommended that
identifiers *begin* with an underscore since C library routines usually
use such names and conflicts may result. Also, some identifiers are
reserved as keywords (auto, break, case, char, ... ).
[color=blue][color=green]
> > How do I set the two MSB in value to the two LSB in 2bits without
> > changing any other bits in value?
> >
> > <mytry>
> > value &= 0x3F; //set those two bits to zero
> > value |= (2bits<<6);
> > </mytry>[/color]
>
> Looks good to me. However, it isn't very interesting, since the two
> bits that you are trying to set in 'value' are already set you way
> want them.[/color]
Gak! I need a better proofreader.
[color=blue]
> Observe:
>
> 0xBD = 10111101
> ^^
> 0x02 = 00000010
>[color=green]
> > Do I have to clear(or set) those two bits first?[/color]
>
> You must clear them first, as you did in your example.[/color]
--
Tim Hagan |