/ Forside / Teknologi / Udvikling / C/C++ / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
C/C++
#NavnPoint
BertelBra.. 2425
pmbruun 695
Master_of.. 501
jdjespers.. 500
kyllekylle 500
Bech_bb 500
scootergr.. 300
gibson 300
molokyle 287
10  strarup 270
What does this line mean (part II)....
Fra : holst


Dato : 08-05-01 13:22

if (message.message & 0x0004)

Is message.message & 0x0004 a statement?? And what does it mean??

thanks,
Allan, newbie in c-programming



 
 
Bertel Lund Hansen (08-05-2001)
Kommentar
Fra : Bertel Lund Hansen


Dato : 08-05-01 13:41

holst skrev:

>if (message.message & 0x0004)

message.message is a variable (message) in a struct (message).
The programmer is not good at finding descriptive variable names.

& is a bitwise operator, AND.

0x means that the number is written i hexcode, but it might as
well have been written as 4.

   Decimal;   Binary:
    137      10001001
    4      00000100
   ------------------------------
137 & 4: 0      00000000

   Decimal:   Binary:
    173      10101101
    4      00000100
   ------------------------------
137 & 4: 4      00000100

>Is message.message & 0x0004 a statement?

Yes, for proper values of "statement".

>And what does it mean?

That all other bits than the 2nd one (count from right and start
with number 0) are turned off.

God fornøjelse ... nå nej, jeg glemte jo at du er engelsk (ved
Auc?)

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

holst (08-05-2001)
Kommentar
Fra : holst


Dato : 08-05-01 14:35

Thank for your helping, but the last thing you wrote I don't quite
understand


"Bertel Lund Hansen" <nospamto@lundhansen.dk> wrote in message
news:l4qffts3pjvp75rlie21tft6m8b40b89h0@sunsite.auc.dk...
> holst skrev:
>
> >if (message.message & 0x0004)
>
> message.message is a variable (message) in a struct (message).
> The programmer is not good at finding descriptive variable names.
>
> & is a bitwise operator, AND.
>
> 0x means that the number is written i hexcode, but it might as
> well have been written as 4.
>
> Decimal; Binary:
> 137 10001001
> 4 00000100
> ------------------------------
> 137 & 4: 0 00000000
>
> Decimal: Binary:
> 173 10101101
> 4 00000100
> ------------------------------
> 137 & 4: 4 00000100
>
> >Is message.message & 0x0004 a statement?
>
> Yes, for proper values of "statement".
>
> >And what does it mean?
>
> That all other bits than the 2nd one (count from right and start
> with number 0) are turned off.
>
> God fornøjelse ... nå nej, jeg glemte jo at du er engelsk (ved
> Auc?)
>
> --
> Bertel
> http://lundhansen.dk/bertel/ FIDUSO: http://fiduso.dk/



Claus Brinch Jensen (11-05-2001)
Kommentar
Fra : Claus Brinch Jensen


Dato : 11-05-01 12:22


>
> >Is message.message & 0x0004 a statement?
>
> Yes, for proper values of "statement".
>
> >And what does it mean?
>
> That all other bits than the 2nd one (count from right and start
> with number 0) are turned off.

This is not entirely correct, no bits are flipped here.

(message.message & 0x0004) is a boolean statement that is true if the 3rd
bit is set in message.message and false otherwise.

Claus



Bertel Lund Hansen (12-05-2001)
Kommentar
Fra : Bertel Lund Hansen


Dato : 12-05-01 10:16

Claus Brinch Jensen skrev:

>This is not entirely correct, no bits are flipped here.

Du har ret.

--
Bertel
http://lundhansen.dk/bertel/   FIDUSO: http://fiduso.dk/

Søg
Reklame
Statistik
Spørgsmål : 177501
Tips : 31968
Nyheder : 719565
Indlæg : 6408522
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste