conversion

  • Thread starter Thread starter Morten Wennevik
  • Start date Start date
M

Morten Wennevik

Hi Frazer,

You are confusing | (OR) with & (AND)

& will set bits to 1 if both bits are 1, otherwise it will be 0
1 will set bits to 1 if one or both of the bits are 1, otherwise 0


100 (4)
&
001 (1)
____
000 (0)
-----------------------------
100 (4)
|
001 (1)
____
101 (5)

Happy coding!
Morten Wennevik [C# MVP]
 
Frazer said:
hi how does this work

Console.WriteLine(4 & 1);
Console.WriteLine(4 & 3);
Console.WriteLine(4 & 7);
gives me the output
0
0
4

is this doing binary addition? i would like to knw what it does internally
to 4 & 1 to produce 0
thnx

i thought its doing binary addition
100 (4)
001 (1)
____
101 (5)

but its not.
thnx

It's not doing binary addition, it's doing a bitwise AND operation.

For example:

101
111
&
 
Hi Frazer,

Could you correct your clock? your post always are on top as they are one
day ahead of the rest ;)

Cheers,
 
Ignacio Machin ( .NET/ C# MVP ) said:
Hi Frazer,

Could you correct your clock? your post always are on top as they are one
day ahead of the rest ;)

Why isn't it the server who give the date ? It would be better.
 
Frazer said:
is this doing binary addition? i would like to knw what it does internally
to 4 & 1 to produce 0
thnx

i thought its doing binary addition

If you're developing for Intel x86 (which you most probably are), the Intel
instruction set contained the instructions for AND, OR, NOT and other
bitwise operations from the early days. So no, in this case your bitwise AND
results in a single CPU instruction (theoretically, unless there was some
way to add bloat within the framework).
 
hi how does this work

Console.WriteLine(4 & 1);
Console.WriteLine(4 & 3);
Console.WriteLine(4 & 7);
gives me the output
0
0
4

is this doing binary addition? i would like to knw what it does internally
to 4 & 1 to produce 0
thnx

i thought its doing binary addition
100 (4)
001 (1)
____
101 (5)

but its not.
thnx
 
The server does, or at least these posts are put in the correct order on
Opera.
So I guess there must be some timestamp on them from the server, somewhere.

Happy coding!
Morten Wennevik [C# MVP]
 
Back
Top