How to specify a binary number in source code ?

Other misc things
Post Reply
norecess
Member
Posts: 73
Joined: Thu Mar 20, 2008 12:58 am

How to specify a binary number in source code ?

Post by norecess »

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 :)
stefano
Well known member
Posts: 2137
Joined: Mon Jul 16, 2007 7:39 pm

Post by stefano »

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>
norecess
Member
Posts: 73
Joined: Thu Mar 20, 2008 12:58 am

Post by norecess »

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

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

Code: Select all

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
};
User avatar
dom
Well known member
Posts: 2076
Joined: Sun Jul 15, 2007 10:01 pm

Post by dom »

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.
Post Reply