![]() |
Signed Ints??
Has anyone had any experience using negative numbers in their code? I remember trying to do something with negative numbers on the eduBOT and I think I ran into trouble. I was thinking that maybe if you declared it
signed int variable; then maybe it would work.... I'm not sure though. Any suggestions? Thanks. Bill |
Re: Signed Ints??
Yes, you can used signed ints in your code. We're using a header file with the following types defined in it:
Code:
//data type definitions for integers - C18 |
Re: Signed Ints??
Kinda on a similair topic, how can you create a single-bit variable - kinda like a bool - using c?
This whitepaper says you can use individual bits like so: Code:
struct bits { |
Re: Signed Ints??
Quote:
|
Re: Signed Ints??
the problem with having a single bit variable is that memory allocation works in bytes - you create a variable, it's gonna take up at least a byte no matter how you look at it. thus, you either have to tell the compiler explicitly to put 8 1-bit variables together (i.e. using struct to create a bitfield), or just go with byte-long variables and just give them a 0 or 1 value, using an unsigned char.
|
Re: Signed Ints??
I'm not sure if you had it without the signed part of it, but I think this compiler is a little weird in that it defaults to unsigned. So, you have to include the signed if you want negative. Of course, like every single one of my posts, I could be wrong.
|
| All times are GMT -5. The time now is 04:23. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi