dealing with numbers that go negative (two's compliment)
James Long
Posts: 1,181
OK....I basically stick with Spin....because I just don't have time to learn PASM.
I've hit a problem, that until this point, I have not encountered.
A number that can go negative, and when it does, it is in two's compliment.
How does a programmer let the chip know if the items goes to two's compliment?
I'm sort of confused.....as how to prevent the program from thinking the number just jumped to some huge unreasonable number.
I'm·a little rusty with respect to programming....so be easy on me.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother LLC (SMT Assembly Services)
I've hit a problem, that until this point, I have not encountered.
A number that can go negative, and when it does, it is in two's compliment.
How does a programmer let the chip know if the items goes to two's compliment?
I'm sort of confused.....as how to prevent the program from thinking the number just jumped to some huge unreasonable number.
I'm·a little rusty with respect to programming....so be easy on me.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother LLC (SMT Assembly Services)
Comments
Ok.....I see....so my little testing (Hyperterminal) is just a formating problem for the output for me.
Thanks for the reply......I didn't actually think about it that way.....but that makes sense.
I will have to put some led output and test the program to make sure the limit's are working right. I could go back and try to format the output....but it is not that important.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother LLC (SMT Assembly Services)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
So I have the numbers shown on Hyperterminal.....but I would like to format them to be signed.
What is the best way to do this?· Just use the "~~" (the numbers are 16 bit)· ?
It is important, because these number will at some point be stored in a file, And I would like to get the formating issue worked out.
I'm not performing any calculation with the numbers at this point.....just recieving them from an accelerometer, and displaying them.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother LLC (SMT Assembly Services)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Paul Baker
Propeller Applications Engineer
Parallax, Inc.
Ok....I'll modify my code....and see if I can get it to work out. If not...i'll be posting code here...to see if you guys can help out.
I've been spending too much time on the SMT business....and not on my projects. Oh well.....as life goes.
James L
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
James L
Partner/Designer
Lil Brother LLC (SMT Assembly Services)
As I understand it though:
All variables not declared as bytes or words are longs. All longs are signed.
If you RDbyte or RDword the source is treated as unsigned and the result is always positive.