z88dk forums

z80 Development Kit

You are not logged in.

  • Index
  •  » Misc
  •  » How to specify a binary number in source code ?

#1 2008-04-24 16:14:58

norecess
Member
From: Montreal, Canada
Registered: 2008-03-20
Posts: 73
Website

How to specify a binary number in source code ?

Hi,

int a = 0x10 => OK
int a = 10 = > OK
int a = 0b10 => KO!

GCC authorizes binary numbers through the 0bXXXXXXXX convention - is there something similar for z88DK's C compiler ?

Thank you smile

Offline

 

#2 2008-04-24 17:42:49

stefano
Administrator
Registered: 2007-07-16
Posts: 710

Re: How to specify a binary number in source code ?

What about mixed C and ASM ?

<code>
#include "stdio.h"

extern char mydata[];

#asm
._mydata
defb    @10000111
defb    @10001000
defb    0 ; String termination
#endasm

main()
{
  printf("%s",mydata);

}
</code>

Offline

 

#3 2008-04-24 18:05:00

norecess
Member
From: Montreal, Canada
Registered: 2008-03-20
Posts: 73
Website

Re: How to specify a binary number in source code ?

Honestly, I don't find this solution very elegant smile (even if it works).

Unfortunately, this does not work in the context I want to use it :

Code:

enum ESpriteMode
{
    MODE_160_160 = 15, // 0b00001111
    MODE_160_320 = 14, // 0b00001110
    MODE_160_640 = 13, // 0b00001101

    MODE_320_160 = 11, // 0b00001011
    MODE_320_320 = 10, // 0b00001010
    MODE_320_640 = 9, // 0b00001001

    MODE_640_160 = 7, // 0b00000111
    MODE_640_320 = 6, // 0b00000110
    MODE_640_640 = 5  // 0b00000101
};

Offline

 

#4 2008-04-24 22:12:46

dom
Administrator
Registered: 2007-07-15
Posts: 743
Website

Re: How to specify a binary number in source code ?

I didn't know you could do that in gcc!  - I've always used hex or left shifted 1 to get the correct values.

From a brief glance at the code, it doesn't look too tricky to add, give me a poke in a months time and I'll add it in.

Offline

 
  • Index
  •  » Misc
  •  » How to specify a binary number in source code ?

Board footer

Powered by PunBB
© Copyright 2002–2005 Rickard Andersson