Mail Archives: djgpp/1999/02/03/19:05:33
Hi Eli, onsdag, den 3 februari 1999, you wrote:
> You forget that C promotes all integral data types to int's in an
> expression. In other words, ((tmp << 2) >> 2) is a no-op, since tmp is
> loaded into a 32-bit register, where the high two bits aren't shifted out
> by the innermost parentheses. In the first example, the 2 high bits are
> chopped off when you store the result of (tmp << 2) into an 8-bit
> variable.
yeah, i solved the problem later on, guess i was to quick to ask for
help, thanks anyway :-)
> Btw, to reset bit 6, which is what you seem to want, you don't need to go
> to such great lengths. All you need is this:
> bittmp = tmp & 0xCF;
hm, this is not true,
0xCF = 11001111 in binary,
i don't see how this could reset bit 6,
in fact it doesnt,
for example
0xFF & 0xCF = 11001111
0x10 & 0xCF = 00000000
well, i got the function working at least, here it is:
#define RBIT(c,b) ((uchar) (c >> (1+b)) << (1+b)) | ((uchar) (c << (8-b)) >> (8-b))
#define SBIT(c,b,b2) (((uchar) (c << (8-b))) >> (8-b)) | (((uchar) (c >> (1+b))) << (1+b)) | b2
RBIT(c,b) resets bit 'b' in char c
SBIT(c,b,b2) sets bit 'b' in char c, need to OR it with b2 also, wich
is 0x1 for bit 0, 0x2 for bit 1, 0x4 for bit 2 etc..
i'm sure it can be solved more easy, but i'm not that
talent in math so this is what i managed to code :-)
/anarko <anarko AT flashback DOT net>
---------------------------------------------------------
Personal homepage: http://www.flashback.net/~anarko/
PGP Public key: http://www.flashback.net/~anarko/pgp/anarko.asc
ICQ UIN#: 3299208 (anarko)
- Raw text -