Dark Bit Factory & Gravity

PROGRAMMING => C / C++ /C# => Topic started by: Clyde on March 10, 2009

Title: [C++] Hex And Binary
Post by: Clyde on March 10, 2009
Anybody know what the Hex and Binary symbols are please?

In FreeBASIC they are &H for Hex, and &B for Binary.
In Blitz they are the same symbol of $.

Thanks again,
The Little Fuzzy Wuzzy.
Title: Re: [C++] Hex And Binary
Post by: benny! on March 10, 2009
@Clyde:

For Hex use 0x as prefix.
For bin I do not know. AFAIK there is no
explicit syntax - but maybe I am wrong  ::)
Title: Re: [C++] Hex And Binary
Post by: Shockwave on March 10, 2009
Benny is right, there is no explicit syntax for binary numbers, but clyde, you should be using hex anyway :)
Title: Re: [C++] Hex And Binary
Post by: Clyde on March 11, 2009
thanks for the info :)
Title: Re: [C++] Hex And Binary
Post by: Jim on March 14, 2009
Yep, 0x prefix for hex, but no binary, you can do macros like:
Code: [Select]
#define BIN(a,b,c,d,e,f,g,h) (((a)<<7)|((b)<<6)|((c)<<5)|((d)<<4)|((e)<<3)|((f)<<2)|((g)<<1)|(h))
BIN(1,0,1,0,1,1,1,1)

will then work.

Interestingly C and C++ support octal as well using 0 prefix.  So 010 is actually 8 in decimal.

Jim