Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #10272

Re: datatype for bit flags

From jacob navia <jacob@spamsink.net>
Newsgroups comp.lang.c, comp.lang.c++
Subject Re: datatype for bit flags
Date 2011-09-15 10:12 +0200
Organization lccwin
Message-ID <j4sc0l$2n2$3@speranza.aioe.org> (permalink)
References <j4s877$2a0$1@dont-email.me> <j4s9c0$scv$1@speranza.aioe.org> <j4sbhc$j9e$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


Le 15/09/11 10:03, Gr a écrit :
>
> Are you saying that whenever I am doing bit operations, it's better to
> use unsigned data types instead of signed ones.
>

Yes, since the data is not an integer, just a collection of
flags. That way I am sure I can use CHAR_BIT*8 flags with
no problems if I do shifts, etc.


Obviously for ANDing the last 4 bits either declaration is OK.

> I guess if you are left shifting or right shifting, then using unsigned
> is better. How if you are just & (to check if a bit is set) & | (to set
> a bit), does it make a diff if you use a signed datatype or an unsigned
> one? I guess signed type would you give you one less bit to work with as
> compared to an unsigned one, but other than that would it make a
> difference?
>

Not at all.

[snip]

>
>> By the way are you sure you want
>> code = code & 1
>> This sets to zero all bits but the last... If the last was zero
>> it remains zero.
>>
>> Or maybe you intended
>> code = code | 1;
>>
>> That *sets* the last bit to 1.
>
> Yes, true.
>
> All the &'s in my psuedocode should have been |'s.
>

OK, now it is clearer what you want to do.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

datatype for bit flags Gr <g@g.com> - 2011-09-15 12:37 +0530
  Re: datatype for bit flags jacob navia <jacob@spamsink.net> - 2011-09-15 09:26 +0200
    Re: datatype for bit flags Gr <g@g.com> - 2011-09-15 13:33 +0530
      Re: datatype for bit flags jacob navia <jacob@spamsink.net> - 2011-09-15 10:12 +0200
  Re: datatype for bit flags Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-09-15 01:06 -0700
  Re: datatype for bit flags "BartC" <bc@freeuk.com> - 2011-09-15 10:56 +0100
    Re: datatype for bit flags Gr <g@g.com> - 2011-09-15 17:24 +0530
  Re: datatype for bit flags Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-09-16 01:16 +0300
    Re: datatype for bit flags Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-09-16 04:59 -0700
      Re: datatype for bit flags Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-16 20:46 +0000
        Re: datatype for bit flags pete <pfiland@mindspring.com> - 2011-09-16 18:00 -0400
        Re: datatype for bit flags Malcolm McLean <malcolm.mclean5@btinternet.com> - 2011-09-18 05:00 -0700
          Re: datatype for bit flags Jorgen Grahn <grahn+nntp@snipabacken.se> - 2011-09-18 13:36 +0000
      Re: datatype for bit flags "Tony" <nospamme@ever.net> - 2011-09-16 16:47 -0500
        Re: datatype for bit flags pete <pfiland@mindspring.com> - 2011-09-16 18:35 -0400
          Re: datatype for bit flags Keith Thompson <kst-u@mib.org> - 2011-09-16 16:25 -0700
            Re: datatype for bit flags pete <pfiland@mindspring.com> - 2011-09-17 02:35 -0400
              Re: datatype for bit flags Keith Thompson <kst-u@mib.org> - 2011-09-17 14:42 -0700
          Re: datatype for bit flags "Tony" <nospamme@ever.net> - 2011-09-16 19:27 -0500
  Re: datatype for bit flags hanukas <jukka@liimatta.org> - 2011-09-23 03:56 -0700

csiph-web