Go to Post I used to think FIRST was about my learning experiences, but now that I'm out of high school and am a seasoned veteran of FIRST I've realized that this organization is about more than my own enjoyment, it's about the enjoyment of others. - Jeremiah Johnson [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-02-2004, 03:16
mightywombat's Avatar
mightywombat mightywombat is offline
bins? stacking?? NOOOOO!
AKA: Bill Rosemurgy
#0857 (Superior Roboworks)
Team Role: Programmer
 
Join Date: Dec 2003
Location: Houghton, MI
Posts: 93
mightywombat is on a distinguished road
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
__________________
Bill Rosemurgy - Aspiring Programmer and Human Player (stack of 8 in <10 seconds...oh yeah... but I can't shoot for crap.)
www.team857.com
  #2   Spotlight this post!  
Unread 22-02-2004, 10:05
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
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;
So, if you want a 4-byte signed integer you can declare it as a sint32. An unsigned 3-byte integer is a uint24, etc.
  #3   Spotlight this post!  
Unread 22-02-2004, 10:15
DanL DanL is offline
Crusty Mentor
FRC #0097
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: Somerville, MA
Posts: 682
DanL is just really niceDanL is just really niceDanL is just really niceDanL is just really niceDanL is just really nice
Send a message via AIM to DanL
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?
};
but the "itsey: 3;" syntax doesn't seem to work unless you are using it inside a struct. I'm sure there's a way more elegant than using a struct, but can anyone let me know what it is?
__________________
Dan L
Team 97 Mentor
Software Engineer, Vecna Technologies
  #4   Spotlight this post!  
Unread 22-02-2004, 11:50
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Signed Ints??

Quote:
Originally Posted by SuperDanman
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?
};
but the "itsey: 3;" syntax doesn't seem to work unless you are using it inside a struct. I'm sure there's a way more elegant than using a struct, but can anyone let me know what it is?
Well, that's C for you. If you want to work with bits, you're stuck with bitfields as the most elegant solution. Of course, you could use ints and just use macros to get at the bits -- but that is messy, and why not let the compiler do it for you automagically with the bitfield? There's a struct already declared for you by IFI in the default code that gives you access to bits 1 - 8. If you desire true "elegance" might I suggest just hiding everything behind a define statement -- e.g., #define mybit bitfield.bit5.
  #5   Spotlight this post!  
Unread 22-02-2004, 12:42
deltacoder1020's Avatar
deltacoder1020 deltacoder1020 is offline
Computer Guy
AKA: Dav
#1020 (The Indiana Prank Monkeys)
Team Role: Programmer
 
Join Date: Jan 2004
Location: Muncie, Indiana
Posts: 340
deltacoder1020 has a spectacular aura aboutdeltacoder1020 has a spectacular aura about
Send a message via AIM to deltacoder1020
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.
__________________
Team 1020, the Indiana Prank Monkeys (www.team1020.org)
  #6   Spotlight this post!  
Unread 22-02-2004, 14:43
Ryan M. Ryan M. is offline
Programming User
FRC #1317 (Digital Fusion)
Team Role: Programmer
 
Join Date: Jan 2004
Rookie Year: 2004
Location: Ohio
Posts: 1,508
Ryan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud ofRyan M. has much to be proud of
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.
__________________

Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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


All times are GMT -5. The time now is 00:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi