Go to Post Many people follow that advice, as if Ohio is Mordor or something. - Travis Hoffman [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
  #16   Spotlight this post!  
Unread 21-01-2003, 09:23
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Quote:
Originally posted by Dave Flowerday
Also remember that the BASIC Stamp (as well as all the other microcontrollers inside the OI/RC) is only an 8 bit processor.
Isn't the Stamp 16-bit, since it always chews on 16-bits of data at a time? If not, what determines the "bits" of a processor?
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #17   Spotlight this post!  
Unread 21-01-2003, 09:52
Dave Flowerday Dave Flowerday is offline
Software Engineer
VRC #0111 (Wildstang)
Team Role: Engineer
 
Join Date: Feb 2002
Rookie Year: 1995
Location: North Barrington, IL
Posts: 1,366
Dave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond reputeDave Flowerday has a reputation beyond repute
Quote:
Originally posted by rbayer
Isn't the Stamp 16-bit, since it always chews on 16-bits of data at a time? If not, what determines the "bits" of a processor?
The Stamp that we're using is based on a Scenix SX28AC microcontroller which is an 8 bit unit. Typically when someone refers to the "bits" of a processor it is referring to the maximum size of integer that the processor can operate on. What this means is that, at the assembly language level, an 8 bit processor can only perform operations on 8 bit numbers. So the assembly level "add" command on an 8 bit controller can only add 2 8 bit numbers. However, you can still do 16, 32, or whatever bit math by operating on the numbers in 8 bit quantities. So if an 8 bit processor wants to add 2 16 bit numbers, it first adds the lower 8 bits of the two numbers then adds the upper 8 bits of both numbers plus the carry bit from the previous operation. I hope I'm making sense here as I can tell I'm not explaining it very well.

Anyway the bottom line is when the Stamp works with 16 bit values it is really being translated into a series of 8 bit operations inside the microcontroller running the stamp interpreter.
  #18   Spotlight this post!  
Unread 21-01-2003, 11:56
Jeff McCune's Avatar
Jeff McCune Jeff McCune is offline
Alpha Geek
#0677 (The Wirestrippers)
Team Role: Mentor
 
Join Date: Jan 2003
Location: The Ohio State University
Posts: 67
Jeff McCune is on a distinguished road
Send a message via ICQ to Jeff McCune Send a message via AIM to Jeff McCune
Quote:
Originally posted by Rickertsen2
I reallt do hope they do persue something else. Its a big change going from mainly C++ Java and PHP to Pbasic.
It is? Last I checked, PHP, C++ and Java all had IF / ELSE / GOTO control structures... Besides, programming is 90% about high level logic and 10% about syntax. A *good* programmer isn't limited by the language they have in front of them. They can think logically about the problem, come up with a solution, and then translate that solution into whatever syntax they have.

PBasic isn't bad. At least it's not raw assembly.
__________________
Team 677 - The Wirestrippers - Columbus School for Girls and The Ohio State University
EMAIL: mccune@ling.ohio-state.edu

...And all you touch and all you see
Is all your life will ever be...
  #19   Spotlight this post!  
Unread 21-01-2003, 21:15
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
Quote:
Originally posted by Dave Flowerday
The Stamp that we're using is based on a Scenix SX28AC microcontroller which is an 8 bit unit. Typically when someone refers to the "bits" of a processor it is referring to the maximum size of integer that the processor can operate on. What this means is that, at the assembly language level, an 8 bit processor can only perform operations on 8 bit numbers. So the assembly level "add" command on an 8 bit controller can only add 2 8 bit numbers. However, you can still do 16, 32, or whatever bit math by operating on the numbers in 8 bit quantities. So if an 8 bit processor wants to add 2 16 bit numbers, it first adds the lower 8 bits of the two numbers then adds the upper 8 bits of both numbers plus the carry bit from the previous operation. I hope I'm making sense here as I can tell I'm not explaining it very well.

Anyway the bottom line is when the Stamp works with 16 bit values it is really being translated into a series of 8 bit operations inside the microcontroller running the stamp interpreter.
Ah, that makes sense.
What would the resultant of this be, does it overflow, whats the actual resultant though in binary?

01001010 10011101 +
11001010 10100101
^^
20010101 01000010
1 00010101 01000010
00010101 01000010
... any ideas? I haven't had time to look this up. The question always comes up when I'm away from my computer.
__________________
R
  #20   Spotlight this post!  
Unread 21-01-2003, 21:21
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Yes, it will overflow. However, as far as I know there is no program-accessible carry bit that will let you know when this happens. Instead, you will just get the last 16 bits back and that first 1 will be lost.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #21   Spotlight this post!  
Unread 21-01-2003, 21:37
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
hrmm, "you just get the last 16 bits back and that first 1 will be lost"...numbers are better, binary is right to left, don't you mean the "first 16" and "last 1?"

Sorry, my question was for C++ (or binary standard), which I did not state. I was mainly wondering about how - signs are stored in binary.
__________________
R
  #22   Spotlight this post!  
Unread 21-01-2003, 21:48
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
It all depends on what you define as first and last. I was assuming the normal left-to-right reading order. I probably should have said you get the 16 least-significant bits and loose the most significant.

Negatives in binary: two's complement. Basically, invert everything, add 1. For example, to find -1, take 00000001, invert the bits (11111110) and add 1 (11111111). This can either be interpreted as 255 or -1.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #23   Spotlight this post!  
Unread 21-01-2003, 22:10
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
" (11111110) and add 1 (11111111). This can either be interpreted as 255 or -1." Only in PBASIC

Rbayer, notice "Sorry, my question was for C++ (or binary standard)," "how signs are stored in binary."

Hence, a 16 bit integer = 32767 through -32768.

or an unsigned short int which maxes 65535 (16 bits)

which leads me to believe that there is an actual extra bit for signs when compiling in c++.

nevermind, trying to explain my question I figured it out.

00000000 00000000
^ the 32768 (16th bit (n^(16-1))) or the last bit is used for signs.

11111111 11111111 = 65535

65535 + 1 = 00000000 00000000

in signed ints,

11111111 11111111 = -32768
01111111 11111111 = 32767

All of them off counts as the number 0, I think the last one signifies negative and has the value of 1.

ex: 10000000 00000000 = -1, considering 0 is never negative. That's why you get the -32768 instead of -32767

I think this makes sense, correct me if im wrong.


v = (n^(n))-1 -> max unsigned bit integer
range: 0 to v

v = (n^(n-1))-1 -> max signed integer

range: -v+1 to v
__________________
R
  #24   Spotlight this post!  
Unread 21-01-2003, 22:24
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
Quote:
Originally posted by rwaliany
" (11111110) and add 1 (11111111). This can either be interpreted as 255 or -1." Only in PBASIC

Rbayer, notice "Sorry, my question was for C++ (or binary standard)," "how signs are stored in binary."
This is the same for either C or PBASIC. In order to differentiate between 255 and -1, you have to tell the compiler whether you are using a char or an unsigned char. If it's a char, it will interpret it as -1. If it's an unsigned char, it will be 255. Try this:

int main(){
int myNum=-1;

printf("Signed: %d\nUnsigned: %u\n", myNum, myNum);

}

You'll see that when interpreted as signed, it prints -1, as expected. When interpreted as unsigned, it will print 4294967295, which is the largest possible unsigned int (32 1's).

Using a similar program, you can find that -32768 is actually represented as 4294934528, which is 11111111111111111000000000000000.

32768=1000000000000000.

Invert: 0111111111111111.

Add 1: 1000000000000000.

Sign extend to 32-bits: 11111111111111111000000000000000, as expected.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #25   Spotlight this post!  
Unread 21-01-2003, 23:46
rwaliany's Avatar
rwaliany rwaliany is offline
R
None #0691 (HartBurn)
Team Role: Programmer
 
Join Date: Jan 2003
Rookie Year: 2000
Location: http://www.hartrobot.com
Posts: 137
rwaliany will become famous soon enough
"Using a similar program, you can find that -32768 is actually represented as 4294934528, which is 11111111111111111000000000000000."

Note: I said short int, short ints are 16 bits. I do it in short ints, because that's what i'm use to, and I don't feel like writing 32 zeros.

from my experiences when i was 13 or so working on my C server i used short ints.

V this is my experience with them

32767
Before: 0111111111111111

32767 health + 1 health
After: 1000000000000000
-32768 poor guy

Ex: 1111111111111111
-1

-1 + 1
Result: 00000000 00000000
0

Oh, lol, I didn't realize i put
"11111111 11111111 = -32768"
I'm on 6 hours of sleep for 3 days pardon me. Didn't go sleep saturday night.

I don't see the point of the inverse and add 1 you were doing.
__________________
R
  #26   Spotlight this post!  
Unread 22-01-2003, 01:27
rbayer's Avatar Unsung FIRST Hero
rbayer rbayer is offline
Blood, Sweat, and Code
no team (Teamless Orphan)
 
Join Date: Mar 2002
Rookie Year: 2001
Location: Minnetonka, MN
Posts: 1,087
rbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of lightrbayer is a glorious beacon of light
Send a message via AIM to rbayer
I'm not going to argue over this one: x86 (and most other architectures) use two's complement for representing negative numbers. Under that system, you invert all the bits and add 1. It's just the way it is. Don't believe me? Go ahead and read this.
__________________
New C-based RoboEmu2 (code simulator) available at: http://www.robbayer.com/software.php
  #27   Spotlight this post!  
Unread 22-01-2003, 03:49
Gobiner Gobiner is offline
Registered User
#0753 (High Desert Droids)
 
Join Date: Nov 2002
Location: Bend, Oregon
Posts: 54
Gobiner is an unknown quantity at this point
Send a message via ICQ to Gobiner Send a message via AIM to Gobiner
Crap, and here I was thinking all along that the bit count of a processor was the number of bits it could use to access memory. 0x123456 vs 0x123456789abc. I guess I never did the math or never realized that 268435455 memory handles was probably enough for whatever you'd use an Itanium for.
__________________
0N3 1337 PR0G|24MM1N6 N1NJ4
  #28   Spotlight this post!  
Unread 22-01-2003, 08:00
redbeard0531 redbeard0531 is offline
Registered User
#0686 (Bovine Intervention)
 
Join Date: Jan 2003
Location: New Market, MD
Posts: 40
redbeard0531 is an unknown quantity at this point
Send a message via AIM to redbeard0531
Cheap formula for twos compliment binary: 256 + x , where256 is 2 raised to the number of bits(8 here), and x is the NEGATIVE number to be converted. I used this in a comp sci class once and it worked great.

Last edited by redbeard0531 : 22-01-2003 at 08:09.
  #29   Spotlight this post!  
Unread 26-01-2003, 23:56
Anthony Kesich's Avatar
Anthony Kesich Anthony Kesich is offline
Programmer Turned Engineer
AKA: SonKenshin
#1097 (Site 3 Engineernig)
Team Role: Leadership
 
Join Date: Jan 2003
Rookie Year: 2003
Location: Sacramento, CA
Posts: 186
Anthony Kesich has a spectacular aura aboutAnthony Kesich has a spectacular aura about
Send a message via AIM to Anthony Kesich
Red face sheer joy (or boredom)

See, i learned basic programming and logic being bored in the back of my math class (geometry, alg II and pre-calc) and creating games and solvers. My friends and classmates all loved me for it. Anyways, it set me up for real programming, since the TI-83 plus language was very limited, i had to come up with everything myself, except for basic if, then statements, goto, inputs, and displays. So yeah, programming is 10% knowing the language, 40% logic, and 50% luck and ingenuity.

-Anthony
__________________
C is screwing up my English--I'm ending all my sentences in semi-colons;

Horray for most things! -George Carlin

"Sure, I'll play rugby. Besides, I have a lot of experience running from really big guys who want to cream me." -Me, Freshman year
  #30   Spotlight this post!  
Unread 27-01-2003, 04:29
Adam Krajewski's Avatar
Adam Krajewski Adam Krajewski is offline
Registered User
AKA: Jewski
None #0857 (Superior Roboworks) / Team #0068 (Truck Town Thunder)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Da U.P., Eh
Posts: 83
Adam Krajewski is on a distinguished road
I am a former PBASIC hater, now reformed.
While it has its limitations, with clever programming you can do just about anything. GOTOs and all, it's still nicer than VisualBASIC.

Adam
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
Obscure PBASIC for RoboEmu rbayer Programming 1 28-03-2003 23:57
PBasic 2.5 vs. 2.0 Anthony Kesich Programming 6 09-02-2003 22:06
RoboEmu v.1a (another PBASIC emulator) rbayer Programming 0 07-07-2002 00:45
emulationFIRST (aka PBasic emulator) Matt Leese Programming 5 30-06-2002 12:06
Another PBASIC Question Ian W. Programming 4 31-01-2002 21:36


All times are GMT -5. The time now is 11:21.

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