Jump to content
Sign in to follow this  
Steve_DeGroof

int<->char conversion functions

Recommended Posts

How about built-in functions to help convert chars to ints and back?

 

For example:

int makeInt(char msb, char lsb);

char msb(int value);

 

makeInt(0xaa,0x55) would concatenate the two bytes and return 0xaa55

 

msb(0xaa55) would return 0xaa

 

...or is there already an easy way to do this that I've missed?

Share this post


Link to post
Share on other sites

Yip - if someone could answer this it would be good! Especially for ADC then reading in the char value and trying to compare it with an integer!

Share this post


Link to post
Share on other sites

Guys,

 

whats wrong with:

 

char msbyte;

msbyte = data >> 8;

 

int myint;

myint = a + (b << 8);

 

This generates very efficient code.

 

Regards

Dave

Share this post


Link to post
Share on other sites
Guys,

 

whats wrong with:

 

char msbyte;

msbyte = data >> 8;

 

int myint;

myint = a + (b << 8);

 

This generates very efficient code.

 

Regards

Dave

 

I think the following may be more efficient ?

int temp;

asm

{

movf _adresl, W

movwf _temp

movf _adresh,W

movwf _temp+1

}

 

Its a good point. Built in (inline as well) functions for this kind of thing would probably be quite usefull especially for those who don't want to get into the inline asm stuff.

Share this post


Link to post
Share on other sites

A new macro that builds a 16-bit long value from two 8-bit long values was added to the system header. It will be available in the next BoostC release. (Can't publish it here because the compiler needed a tiny change to support these kind of macros).

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...