Porting arduino libraries

Guys,

I’m trying to port some Arduino libraries over to C# however, my knowledge of both languages is not at an expert level (yet).

The library i’m trying to port uses bitClear and bitSet from the Arduino.
bitSet: [url]http://arduino.cc/en/Reference/BitSet[/url]
bitClear: [url]http://arduino.cc/en/Reference/BitClear[/url]

Are these functions available in C# NetMF ?

Also, it uses micros() from arduino, is this equal to DateTime.Now.Ticks ?

Thanks in advance.

I want to set the third bit in my variable called x

x |= (1<<2);
that is hte same as
x= x |(1<<2);

set this first fit?
x|=(1<<0);

now to clear the forth bit
x &= (~(1<<3));

Is this what you need?

not sure…

bitClear:
[italic]Description[/italic]
Clears (writes a 0 to) a bit of a numeric variable.

[italic]Syntax[/italic]
bitClear(x, n)

[italic]Parameters[/italic]
x: the numeric variable whose bit to clear
n: which bit to clear, starting at 0 for the least-significant (rightmost) bit

[italic]Returns[/italic]
none

bitSet:
[italic]Description[/italic]
Sets (writes a 1 to) a bit of a numeric variable.

[italic]Syntax[/italic]
bitSet(x, n)
[italic]
Parameters[/italic]
x: the numeric variable whose bit to set
n: which bit to set, starting at 0 for the least-significant (rightmost) bit
[italic]
Returns[/italic]
none

Yes that was exactly what I showed you

void bitSet(int x,int n)
{
  x |= (1<<n);
}

This might be a handy thing to have as an extension method so you could just do something like:

myVar.BitSet(2);
myVar.BitClear(3);

//or even

myVar.Mask(0xF0); // which just does a logical AND

Thanks Gus,

So, bitClear will be:


void bitClear(int x, int n)
{
     x &= (~(1<<n));
}

right?

Correct.

Thanks