Jump to content
Sign in to follow this  
Mac

Binary number format in C (CCSv4)?

Recommended Posts

G'day Gentlemen,

 

May I impose to ask how to use a binary number format in C in CCSv4, please? I've tried a few different formats so far but no joy (0b00000001, %00000001, and 000000001b).

 

Cheerful regards, Mike McLaren

Share this post


Link to post
Share on other sites

You can define a function that will convert your "binary" input (long) and return a value.

BIN(00100010)

Or you can waste some time and create include file with 256 binary numbers as definitions :)

#define B00001111 0x0F

#define B00010000 0x10

etc.

Share this post


Link to post
Share on other sites

Thank you very much for the reply and the link. It sounds like the binary number format isn't supported which would explain why I haven't seen it in any of the 430G' example C programs.

 

May I ask if the MSP430 Optimizing C/C++ Compiler v 3.1 User Guide that was referred to in that link is the language manual for the Compiler within CCSv4? Or, is there a CCSv4 Optimizing C/C++ Compiler User Guide I should be looking for, please?

 

Thank you again for your time and kind consideration Gentlemen.

 

Cheerful regards, Mike McLaren

Share this post


Link to post
Share on other sites

Here's an interesting thread about this issue:

http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/t/60157.aspx

 

I guess it boils down to the fact that binary representation isn't oficially supported by the C language. A couple of solutions are offered by the thread. One is that header file with all the defines already made, the other is a macro. I'm not an expert on compilers, but I'd think the header would do the job fine without wasting cpu cycles.

Share this post


Link to post
Share on other sites

Macros will be replaced at compile time so you will not be wasting cpu cycles.

Looks like someone has already created that header file, thanks for the link.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×