Go Down

Topic: Serial print refresh time (Read 2 times) previous topic - next topic

jtw11

#20
May 25, 2012, 10:40 pm Last Edit: May 25, 2012, 10:55 pm by jtw11 Reason: 1
Ah, I was just about to ask that question - one signed, one unsigned. So, I've changed them to both signed - but embarrassingly, I still don't understand the different between signed and unsigned, i'm aware one can contain neg values whilst the other can't. I can't sit here with a command in my code that I don't really know why it's there, even if it works.

I completely understand why I've made some of 'const', so as to prevent the controller putting things in and out of RAM unnecessarily.

I think maybe i'm confused between bytes, ints & longs. Which do I actually need to use here for the millis and intervals. I can't see why I need to sign, or unsign either.

EDIT: Aha, the table on this page seems to explain it! http://www.cplusplus.com/doc/tutorial/variables/

Well no, not really actually - because surely I can just use a 'short' instead, as the value is between 0 and 65535. Then signed or unsigned is simply a sign convention thing. Correct?

All help up until now greatly appreciated!

Arrch

#21
May 25, 2012, 10:54 pm Last Edit: May 25, 2012, 11:02 pm by Arrch Reason: 1
Given two values
Code: [Select]
unsigned short a = 0xD5;
signed short b = 0xD5;


a is interpreted as 213
b is interpreted as -43

This is important in comparison, multiplication, division operations as well as conversions for stuff like Serial prints because how it's interpreted would affect the result.

Addition, subtraction and bitwise operations don't care as the result (in binary) is the same no matter how it's interpreted.

jtw11


Given two values
Code: [Select]
unsigned short a = 0xD5;
signed short b = 0xD5;


a is interpreted as 211
b is interpreted as -43


Am I missing something here, where have the Ds come from?

Arrch

#23
May 25, 2012, 10:58 pm Last Edit: May 25, 2012, 11:02 pm by Arrch Reason: 1

Am I missing something here, where have the Ds come from?

0xD5 is the hex representation of 213 and -43.

Edit: D5 is 213, not 211.

AWOL

The whole example is nonsense.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up