Binary prefixes in C
hi,
does anyone know the binary prefix when it comes to defining one?
For example, for Hexademical representation it is 0x...
for Octal it is 0...
how about binary?
Yes! There are kangaroos in Australia but I haven't seen them...yet
With binary, it''s a suffix , which is b . So 11010001b would mean that''s a binary number.
Actually, while b is a valid suffix in assembly language, it''s not in C. There is no way to put in binary numbers in C/C++ code, as far as I know. But if there is, then I''d like to know too
![](smile.gif)
Some compilers may have provisions for binary constants, but the ANSI standard does not.
February 01, 2001 12:45 PM
And it''s really annoying that there isn''t a way. Hex is your closest bet.
-Mike
-Mike
about 8 years ago, I think I used %... to represent binary in a Borland compiler but I guess that doesn''t work now.
Yes! There are kangaroos in Australia but I haven't seen them...yet
Surely it's not too difficult to write a little function to let you use binary numbers?
Something like:
int Binary(char* binaryString);
Then you could do something like this:
int aNumber = Binary("01010111");
You could even write a macro do make it easier to use.
#define BINARY(n) Binary(#n)
int aNumber = BINARY(01010111)
And here's a sample function:
Andy.
Edited by - andy maddison on February 2, 2001 4:01:14 PM
Something like:
int Binary(char* binaryString);
Then you could do something like this:
int aNumber = Binary("01010111");
You could even write a macro do make it easier to use.
#define BINARY(n) Binary(#n)
int aNumber = BINARY(01010111)
And here's a sample function:
|
Andy.
Edited by - andy maddison on February 2, 2001 4:01:14 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement