modifying and checking bits

I'm moving from the PIC chips to the Arduino, and I am reading your reference page, and I don't see how you can modify a specific bit in a register, and how an if statement can check if a specific bit is set or cleared in a register.

Say I wanted to check bit 4 in the variable "someData", can I do this?

if (someData.4 == 1)
{
 // do something here
}

Or am I forced to do this?

someData = someData & 0b00010000;
if (someData == 0b00010000)
{
 // do something here
}

Efficiency is very important to me, and usually PICs can check a bit, skip a goto command if it's cleared or set, which takes only 2 instructions to do.

Well, if you want to see if any of the bits are set, or if bit 4 is the only one that could be set, just

if (someData)
{
 // do something here
}

If you want to test only bit 4,

if (someData & 0b00010000)
{
 // do something here
}

if you want to modify a bit,

//set bit 4
someData = someData | 0b00010000;
// same thing, more compact C code, but same executable code
someData |= 0b00010000;

Efficiency is very important to me

Me, too. I like to make efficient use of my time spent writing programs. Assembly is incredibly inefficient in that regard.

I find writing in assembly language (especially PIC assembly) is like hitting yourself with a hammer - it feels really good when you stop.

Modern compilers are quite sophisticated, and usually do a better job than a human in generating efficient code. If your architecture has a machine instruction for skipping the next instruction if a test is true, you can bet the compiler knows about it.

-j

Yea I knew I can use or and and to set or clear bits.

So a boolean can be equated to any other types of unsigned variables with 0 being false and anything else being true?

If I want my compiler to check if a byte is exactly so and so, wouldn't it have to check every bit? Say I needed to check if the byte is 0b00010000, would my compiler be smart enough to only check the 4th bit IF the rest of the program does not allow it to be anything else?

I ordered a Diecimila from Adafruit.com and also uChobby.com is sending me a bare bones Arduino for free. I'm looking for a replacement platform for my robots, and programming PICs has been a PITA.

Are the registers of the Atmega168 directly accessible in Arduino's language? Do I need to include my own definitions?

So a boolean can be equated to any other types of unsigned variables with 0 being false and anything else being true?

Correct, except it doesn't matter if they are signed or unsigned. 0 == false, anything else == true.

Are the registers of the Atmega168 directly accessible in Arduino's language?

Yes.

The "Arduino's language" is C, specifically gcc provided by the avr-gcc toolchain. The registers are available by the same names used in the datasheet, AFAIK. I have personally used DDRD, PIND and PORTD to get at the registers for port D.

Arduino is more a combination of library, IDE, and hardware designed to simplify the use of gcc and the Atmel AVR, while maintaining all the power of the two.

-j