Author Topic: [C++] Hex And Binary  (Read 3551 times)

0 Members and 1 Guest are viewing this topic.

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
[C++] Hex And Binary
« 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.
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: [C++] Hex And Binary
« Reply #1 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  ::)
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17414
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: [C++] Hex And Binary
« Reply #2 on: March 10, 2009 »
Benny is right, there is no explicit syntax for binary numbers, but clyde, you should be using hex anyway :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Clyde

  • A Little Fuzzy Wuzzy
  • DBF Aficionado
  • ******
  • Posts: 7271
  • Karma: 71
    • View Profile
Re: [C++] Hex And Binary
« Reply #3 on: March 11, 2009 »
thanks for the info :)
Still Putting The IT Into Gravy
If Only I Knew Then What I Know Now.

Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: [C++] Hex And Binary
« Reply #4 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
Challenge Trophies Won: