byte = 0xff;byte = b00000000;for starters
byte = b00000000;
My question is how do I incorporate binary and hex into Arduino and C? Can anybody provide a few good sample programs that can illustrate hex and binary being used in the Arduino environment?
harkening back to the original PDP11 PDP-8 (and possibly earlier) days
QuoteMy question is how do I incorporate binary and hex into Arduino and C? Can anybody provide a few good sample programs that can illustrate hex and binary being used in the Arduino environment?In standard C, you can cause a number to be interpreted as a hex number by preceding it with a "0x" prefix.In most versions of gcc (which is used by Arduino) you can cause a number to be interpreted as binary by preceding it with a "0b" prefix.In the Arduino environment, there are a set of binary one-byte constants defined using "B" as a prefix.So, 192, B11000000, 0b11000000, and 0xC0 are all the same number.0xDeadBeef is a valid 32bit hex constant. 0b101001000100001000001 is a fine binary number (but rather unreadable.)Don't put leading zeros on your decimal numbers, though. That makes them be read as octal, so 010 would be the same as 8 ! (harkening back to the original PDP11 days, I guess.)
Quoteharkening back to the original PDP11 PDP-8 (and possibly earlier) daysWell, C was originally developed for the PDP11, wasn't it? Octal itself is certainly much older, but I hypothesize that its inclusion in C was directly because C was aimed at PDP11 "systems programming", and the PDP11 was defined/documented/etc in octal.
Please enter a valid email to subscribe
We need to confirm your email address.
To complete the subscription, please click the link in the
email we just sent you.
Thank you for subscribing!
via Egeo 16