- have some general Q's
- can i store signed char's to arrays and luts?
- can i convert a unsigned char or unint to signed with it not remaining positive if i inteded negative for that number position, for instance if i store a unsigned 2 in an array and transfer it over to a signed variable how can i make it be the negative equivelant?
- the thing that i want to do is make a correction table by storing a signed char to a lut, pull it out add it to a unsigned char so i can add and subtract from the unsigned number, i guess if i knew the laws of it it would be obvious but don't know how it works yet,
taking a guess i could store as signed char if possible to lut, pull it out and transfer it to signed int with c code, transfer other unsigned char into signed int, then so all the math with both ending variables being signed, then convert answer back to unsigned to use with the delays as the answer is always gonna be positive?
does that make any sense
signed char questions
Moderator: Benj
- JonnyW
- Posts: 1230
- Joined: Fri Oct 29, 2010 9:13 am
- Location: Matrix Multimedia Ltd
- Has thanked: 63 times
- Been thanked: 290 times
- Contact:
Re: signed char questions
Hi Brandon.
With arithmetic, whether a value is signed or unsigned only makes a difference when performing comparisons, divisions and when it is displayed.
There is no difference in the format of integers when they are stored as signed or unsigned, and this will not affect addition or subtraction in any way - with bytes, 0 minus 1 is always 0xFF, which is either -1 or 255 only when displayed on screen.
Your suggestion will work fine, I think. In C, when you pass a value into a function the type of the argument passed in is irrelevant - it is the type of the parameter the function (such as delay()) expects that matters. So passing a signed integer into a function that expects an unsigned integer will not make a difference to how the function works.
I hope this helps.
Jonny
With arithmetic, whether a value is signed or unsigned only makes a difference when performing comparisons, divisions and when it is displayed.
There is no difference in the format of integers when they are stored as signed or unsigned, and this will not affect addition or subtraction in any way - with bytes, 0 minus 1 is always 0xFF, which is either -1 or 255 only when displayed on screen.
Your suggestion will work fine, I think. In C, when you pass a value into a function the type of the argument passed in is irrelevant - it is the type of the parameter the function (such as delay()) expects that matters. So passing a signed integer into a function that expects an unsigned integer will not make a difference to how the function works.
I hope this helps.
Jonny
-
- Posts: 438
- Joined: Mon Aug 29, 2011 12:26 am
- Location: arizona
- Has thanked: 175 times
- Been thanked: 173 times
- Contact:
Re: signed char questions
i see what you mean, a signed int variable of -2 would actually be a 65534 ms delay, that answers alot of questionsWith arithmetic, whether a value is signed or unsigned only makes a difference when performing comparisons, divisions and when it is displayed
thanks for explaining and i came up with a solution as a shorted example of the whole process