Jump to content

Casting Char to Int


jackchaos
 Share

Recommended Posts

Is it possible to cast from Char to Int?

Like:

unsigned char a = 5;

unsigned int b = 1000;

int c = b * (int)a;
When I try to do such a thing I get the following error when running make:
Compiling main.c
Processor: 18F452
================================================
Linking project
error: missing definition for symbol "__mulint"
ERROR!

Link to comment
Share on other sites

why would you want to store an int in a var char?

I have a lookup table filled with unsigned chars that define the config and behavior of each and every pot. One of the items is a refresh interval that later gets multiplied by 500 (this may change later).

This is the only way I can see how to do it... and yes, I'm doing a multiplication the bad way (a = b*c).

I'm at work right now, but from what I see in this document. If I change my 500 (above) to 512

and do a bit shift like so:

a = 2 << 9; // a is 1024

or

a = 5 << 9; // a is 2560

This would be the equivalent of:

a = 2 * 512;

or

a = 5 * 512;

If this is true, I've solved that problem and I can make the changes when I get home.

Thanks again!

( audiocommander, yes. I meant 'a = 2 * 512;', It's corrected above. Thanks. )

Link to comment
Share on other sites

unsigned char two_dimensional_array[NUM_POTS][NUM_OPTIONS]

The array can only hold one value type. I'm storing all my config here and every value is a char.

I want the option to scale all the update intervals so the interval is later multiplied by another number which is higher than 255.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...
 Share

×
×
  • Create New...