Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Casting to an unsigned char

Tags:

c

types

casting

I'm using MPLab C18 C compiler and getting a syntax error with this code:

hundreds = unsigned char((tick / 100));
tens = unsigned char((tick - (hundreds * 100)) / 10);
ones = unsigned char((tick - (hundreds * 100) - (tens * 10)));

tick is an unsigned int. What I'm attempting is to convert a three digit value over to three individual ASCII values by means of simple division and casting the whole number into my unsigned char variables.

It looks okay to me but I guess I'm missing something.

like image 615
Chef Flambe Avatar asked Jul 04 '26 12:07

Chef Flambe


1 Answers

Casting is done in parentheses:

 hundreds = (unsigned char)(tick/100);
like image 148
MByD Avatar answered Jul 06 '26 03:07

MByD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!