BasicMicro - Forums

www.basicmicro.com
It is currently Mon May 21, 2012 8:36 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Token ?
PostPosted: Sat Dec 31, 2011 3:57 am 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Hi all,
i'm Michael from Germany and my english seems to be not good enough for some documentation ;-)
I've bought an Arc32 and most of the time since now i've tried to get the software speak to the Arc... ;-)
Finally it does...on Win7 64bit...

So..now my question :
What is a token ? I've read it several times and the compiler sometimes ask for it, but i really don't know, what it exactly is...

Sorry for my english, but i hope you understand and can help a basic newbie...

Greetings and a happy new year for everyone

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Sat Dec 31, 2011 11:07 am 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
I've found it....

Thanks


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Mon Jan 02, 2012 11:59 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
So others will know, a token is a single word from a basic command. For example in "pause 1000" both pause and 1000 are tokens.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Tue Jan 03, 2012 3:40 am 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Hi,

You're right... but i think in the english language it explains itself...

By the way...

Any idea how to scale two pairs of numbers with eventually negative results ?
Is there a mapping or anything else ?

Some examples ? ;-)

Thanks for help

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Tue Jan 03, 2012 11:31 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
to scale any numbers by the same amount I'd do something like this:

;when scaling down
number1*100/scale
number2*100/scale

when scaling up
number1*scale/100
number2*scale/100

The *100 and /100 gives me a fixed point of 2 decimal places(your scale needs to be *100) which allows you to have fractional scaling. You can do the same thing in floating point math without the *100/100 but it is more processor intensive. Not sure if this is what you were looking for.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Tue Jan 03, 2012 12:15 pm 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Hm... it seems that i have to be more exactly... ;-)

I'm looking for something like :

A1------------ A2
-30000----0----30000

B1-------------B2
0%------------100%

If i have 32% then i have.... ?

This in code: =(A1+(A2-A1)*(C1-B1)/(B2-B1)) would not work or just in positive direction...
But works fine in Exel ;-)

My value (c1) is sWord...

Thank you for trying to help...

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Wed Jan 04, 2012 11:44 am 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Assuming A1 is always less than A2 and B1 is always less than B2:

C1 = (C1-A1)*(B2-B1)/(A2-A1)

C1-A1 is your offset correction. This will work for any offset, positive or negative. This basically shifts your C1 value range from whatever low value it started at(-30000 in this case) to a 0 low value.
B2-B1 is your new range, which you multiply by(before dividing so your don't lose precision)
A2-A1 is your old range which you divide by

I think your excel formula will only work for positive ranges because this (A1+(A2-A1)) is assuming A1 is always positive. I beleive (C1-B1) is also assuming C1 is always positive. Also I believe you will lose precision using this method as well with integer math. Excel probably does everything in doubles(floating point) so you wouldn't see the loss.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Wed Jan 04, 2012 9:43 pm 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Hi Nathan,

there must be a secret using negative numbers...

For my example your formula will be incorrect, because...

32(c1)- -30000(a1) = +30032
100(b2) - 0(b1) = 100
30000(b2)- -30000(b1)= +60000

30032*100 = 3003200
3003200/60000 = 50... but it has to be -10800

This looks incorrect, or? The Offset could never be negative in your formula... minus with minus is positive...or ?

Where is my fault ? I think I must know how to handle negative numbers...
There must be something you don't tell me... ;-)

I'm sorry but here is something i don' understand...

Grettings

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Thu Jan 05, 2012 1:32 am 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Me again...

I think I have it...

(60000/100)*32(c1) - 30000 = -10800

At least it works in my program...unless + and - are equal...

But if you have pleasure and time some info of working with negative values are helpful...
Or is there a source, where i can broaden my mind ?

Thanks for help...hope it was not annoying...

Greetings

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Fri Jan 06, 2012 3:44 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Yes you missed what I did. You said you wanted to convert a value from range -30000:30000 to 0 to 100% range. So first I correct for the offset(C1-A1).

C1 starts as 32 then C1-A1 = 30032 which is what I want.

Then I multiply by (B2-B1) which gets me 3003200. Then I divide by (A2-A1) which is 60000(30000 - -30000). Divide 3003200 by 60000 = 50.05%. Of course the .05 is truncated because it is integer math.

Just like you show in your last post. That is a correctly range converted value.

I have no idea where you are getting -10800 from since you said you wanted to convert to a 0 to 100% range(eg 0 to 100, -10800 doesn't exist in that range last time I checked).

I can only guess that you didn't actually want to convert a value from one range to another but wanted something else entirely.

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Sat Jan 07, 2012 1:04 am 
Offline
Citizen

Joined: Thu Dec 29, 2011 1:52 pm
Posts: 7
Hi Nathan,

i just want to know how much 32% from a range -30000 to +30000 are...

And in this case i think 50 is not correct... ;-) Sorry for missunderstanding...

You're correct if i want to know how much % your 50,05 are... looks like my 32...

Let's close this thread, 'cos the problem is solved... ;-)

I think in the future there will be more opportunity to answer my questions... ;-)

Thanks a lot for the time you've spended to help me...

Michael


Top
 Profile  
 
 Post subject: Re: Token ?
PostPosted: Sat Jan 07, 2012 2:24 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 11:00 am
Posts: 903
Location: Temecula, CA
Ok. Thats not what you asked for. You want the percentage of some value(doesn't matter if its signed or not. That is completely different from what you asked for and your example didn't make it any clearer. :(

C1 * percentage / 100

Thats it. Use signed variables(longs are signed as are sword and sbyte).

given a C1 of -20000 and percentage of 32 = -6400

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO