![]() |
binary in C
Does anyone know if it's possible to use binary numbers in C? Of course, it's just to make it easier to read the source. I'm doing some bitwise operations and 218 or 0xDA just isn't as meaningful as 11011010.
|
Re: binary in C
Quote:
Most people who write a lot of software will tell you that 0xDA is much easier to read than 11011010. |
Re: binary in C
I'm 1200 miles from my K&R right now...
0b11011010 should be equivalent to 0xDA N'est-ce pas? |
Re: binary in C
Quote:
My advice still applies though: get used to hex, it's what everyone else uses ;) |
Re: binary in C
Quote:
I agree with Dave that the hexadecimal form is much better once you get used to it. You probably know it, but for the ones that do not, each hex symbol represents 4 bits. Once you realize that, it just isn't magic anymore. |
Re: binary in C
0b should work. It's not ANSI C, but many compilers understand it. gcc compiles it fine. Dunno about C18 - I usually go out of my way to avoid binary.
http://refcards.com/refcards/c/c-refcard-letter.pdf George |
Re: binary in C
Well, I'm using SDCC. I'd use C18, but it doesn't work for the 16F series PICs. I just tried 0b and it didn't like it. I guess I'll have to stick to hex or decimal.
|
Re: binary in C
The gcc port for Atmel AVRs supports it no questions asked, it's actually fairly used in the examples I saw so 0b works there.....
No support in SDCC? Darn I was gonna use it for this 16F I got sitting here. Oh well... |
Re: binary in C
I sometimes use a calculator to convert from binary to hex and then write the binary equivalent in a comment by the hexadecimal value. For example:
Code:
int bit2mask = 0x04; //00000100b |
Re: binary in C
Code:
#define b00000000 0x00 |
| All times are GMT -5. The time now is 04:32. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi