Casting Char to Int

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!

Never mind, I found this document.

http://www.midibox.org/dokuwiki/doku.php?id=stryd_one_codeblocks

Which introduces me to Code:Blocks and I believe the included LIB is what’s helping me.

You guys are great.

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

http://www.midibox.org/dokuwiki/doku.php?id=c_tips_and_tricks_for_pic_programming

see Arithmetic Calculations :wink:

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

http://www.midibox.org/dokuwiki/doku.php?id=c_tips_and_tricks_for_pic_programming

see Arithmetic Calculations

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

I’m sure you mean a = 2 * 512, then it’s correct and you’ll save a lot of codespace and calculating power this way :wink:

Cheers!

Michael

out of sheer morbid curiosity - why store the var in a char and not an int?

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.

cheers - that makes sense to me now…