|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||||
|
|||||
|
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 |
|
#2
|
|||
|
|||
|
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 //uchar //size: 8 bits (1 byte) //range: 0 to 255 typedef unsigned char uchar; //schar //size: 8 bits (1 byte) //range: -128 to 127 typedef signed char schar; //uint16 //size: 16 bits (2 bytes) //range: 0 to 65535 typedef unsigned int uint16; //sint16 //size: 16 bits (2 bytes) //range: -32768 to 32767 typedef signed int sint16; //uint24 //size: 24 bits (3 bytes) //range: 0 to 16,777,215 typedef unsigned short long uint24; //sint24 //size: 24 bits (3 bytes) //range: -8,388,608 to 8,388,607 typedef signed short long sint24; //uint32 //size: 32 bits (4 bytes) //range: 0 to 4,294,967,295 typedef unsigned long uint32; //sint32 //size: 32 bits (4 bytes) //range: -2,147,483,648 to 2,147,483,647 typedef signed long sint32; |
|
#3
|
||||
|
||||
|
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 {
unsigned int itsy: 3; // Use 3 bits as the variable ?itsy?
unsigned int bitsy: 3; // Use 3 bits as the variable ?bitsy?
unsigned int teensy: 1; // Use 1 bit as the variable ?teensy?
unsigned int weensey:1 // Use 1 bit at the variable ?weensy?
};
|
|
#4
|
||||
|
||||
|
Re: Signed Ints??
Quote:
|
|
#5
|
||||
|
||||
|
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.
|
|
#6
|
||||
|
||||
|
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| My team is registered and signed up for Rutgers(rookie)! | Erodge | General Forum | 5 | 11-10-2002 10:13 |
| Attn: ALL TEAMS WHO SIGNED UP FOR THE QUINCY SCRIMMAGE!!!!!! | archiver | 2001 | 1 | 24-06-2002 00:47 |
| TRADE ITEMS--EXCLUSIVE--MOE'S SIGNED SOCKS & MORE | archiver | 1999 | 2 | 23-06-2002 22:37 |
| Improving PBASIC: Request for Comments | Greg Ross | Programming | 19 | 16-02-2002 22:14 |