NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Basic Electronics » HELP

June 04, 2012
by mikeduff76
mikeduff76's Avatar

OK i want to know if i can use binary numbers in a code

June 04, 2012
by hevans
(NerdKits Staff)

hevans's Avatar

Hi mikeduff76,

I think you are asking if you can write binary literals into your C code. The answer is no, the C language does not have a way of writing binary literals, however you can write hex literals by prefixing them with 0x. Once you get used to it, its pretty easy to convert between the hex and binary representations of a number.

Humberto

June 04, 2012
by pcbolt
pcbolt's Avatar

mike -

Some compilers may let you get away with using this format:

uint8_t test = 0b01001001;

I've gotten errors using this with "cl.exe" but not with "gcc" in MinGW. I have not tested it with "avr-gcc".

June 05, 2012
by Rick_S
Rick_S's Avatar

The 0b prefix works fine. I have used it before. Sometimes it makes the logic a bit easier to "see".

Rick

June 05, 2012
by mikeduff76
mikeduff76's Avatar

ok well i am actully using it for a airplane with the power source from the nerd kit so it dosent afect my nerd kit

June 11, 2012
by mikeduff76
mikeduff76's Avatar

hi

Post a Reply

Please log in to post a reply.

Did you know that you can turn a $20 digital scale into a live weight sensor using our kit with a few extra parts? Learn more...