On 2 Jun 2003 at 1:43, Raúl Gutiérrez Segalés wrote: Date sent: Mon, 2 Jun 2003 01:43:32 -0400 (PYT) From: Raúl Gutiérrez Segalés <rau@campoalto.edu.py> To: <suse-programming-e@suse.com> Subject: Re: [suse-programming-e] working with bits
On Mon, 2 Jun 2003, Raúl Gutiérrez Segalés wrote:
Hi,
I am trying to do a NOT operation but it doesnt seem to work well:
Sorry I meant 1's complement.
Actually I am still reading Jerry's function (getone()) and my trying to , breaking my head, understand this two assignations:
newflags.c_cflag |= (CLOCAL | CREAD); newflags.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
The first one is very obvious since it is a simple oring which just adds the options but second one has an AND but first it does a 1's complement so I cant actually see the logic behind it..
Any one has mercy of this poor learner ?? :)
Thanks once again,
Raul
[snip...] It's not as difficult as it looks at first - break it down into two bits: ~(ICANON | ECHO | ECHOE | ISIG) This gives us a mask flag set that has all the bits set to one -except- ICANON, ECHO, ECHOE and ISIG, which are set to zero. OK, we now and (&) our mask flag set with the target set. Remember with anding we need both target and mask set bits set to one for the flag to be set to one in the result. This means that ICANON, ECHO, ECHOE and ISIG will be set to zero, since we set their bits to zero in the mask. It also means that any other bit in the target that was originally set to one will remain set to one (since both mask and target bits will be set to one) while result bits set to zero int the target will be left at zero (because only the bit in the mask is set to one). So, the net effect is that the bits corresponding to ICANON, ECHO, ECHOE and ISIG are cleared (set to zero) without affecting the settings any of the others bits in the result flag set. Hope that helps <g> alan -- http://www.ibgames.net/alan Registered Linux user #6822 http://counter.li.org Winding Down - Weekly Tech Newsletter - subscribe at http://www.ibgames.net/alan/winding/mailing.html