Entire Forum This board This topic Members Entire Site
 Pages: [1]
 Author Topic: help about picbasic  (Read 2706 times) 0 Members and 1 Guest are viewing this topic.
mohsen
Guest
 « on: April 05, 2008, 09:02:56 09:02 »

hi
how I can work with numbers thet is bigger then one word (65536) in pic basic

 Logged
mississippi1
Newbie

Muted
Offline

Posts: 26

Thank You
-Given: 24

 « Reply #1 on: April 06, 2008, 11:04:50 11:04 »

Than take 2 words, and if you cross boundary of the first word than add 1 to the second word.
 Logged
pickit2
Moderator
Hero Member

Offline

Posts: 4062

Thank You
-Given: 627

There is no evidence that I muted SoNsIvRi

 « Reply #2 on: April 06, 2008, 01:24:10 13:24 »

hi
how I can work with numbers thet is bigger then one word (65536) in pic basic

just use float
 Logged

Note: Did you buy a \$5 key to by-pass a please invite me request   Then you forget to post in the forum, then your account maybe resticted
TomJackson69
Active Member

Offline

Posts: 221

Thank You
-Given: 23

 « Reply #3 on: April 16, 2008, 02:52:00 02:52 »

just use float

Hi Mohson,

Take your large decimal number and devide for 65536 (\$FFFF), put the answer into HighWord, the remainder put in LowWord.

Ex)
LargeNumber = float        / define variables
HighWord      = word
LowWord       = word

Now in your program do some calculation and get the data in the variable LargeNumber. Let say LargeNumber now = 987654.

Take     987654
--------  = 15.07040405
65536

Now put HighWord = 15
And       LowWord  = 4614    (.07040405 x 65536 = 4613.9999999)

Or you can convert your LargeNumber yo HEX number. 987654 =\$F1206 (in Basic you must have Dec to Hex convert function.

Now HighWord = \$0F = 15
And  LowWord  = \$1206 = 4614  (HEX number is nicer)

Hope that help,

Tom

Sory I don't have PICbasic (know a little in Proton Basic)

 Logged

Con Rong Chau Tien
Bitburner
Newbie

Offline

Posts: 10

Thank You
-Given: 0

 « Reply #4 on: April 16, 2008, 06:28:01 06:28 »

hi
how I can work with numbers thet is bigger then one word (65536) in pic basic

V2.50
With the latest versions of the PICBASIC PRO Compiler there is now a signed, long variable type. Each long variable is made up of 4 sequential bytes in memory - thatβs 32 bits. The numeric values that can be represented in a long variable range from -2147483648 to 2147483647, or in some cases, from 0 to 4294967295.

For the non-long version of the compiler (PBPW.EXE), temporaries are word-sized. For the long version of the compiler (PBPL.EXE), temporaries need to be long sized.

Code:
Average Var Long
L1 = 123456 β This is 123.456 in fixed point form
L2 = 234567 β This is 234.567 in fixed point form
L3 = -456789 β This is -456.789 in fixed point form
Average = (L1 + L2 + L3) / 3
Lcdout Sdec (Average / 1000), β.β, Dec3 ((Abs Average) // 1000))

There are some specific commands that can benefit from a larger variable size.
While all the commands can now accept longs as any of their parameters, longs can be helpful in commands such as Count, Pause, Pulsin, Pulsout, Rctime, Shiftin and Shiftout.
In the Count command, for example, a long variable can store a count far larger than the previous limit of 65535 using a word variable.
Shiftin and Shiftout can now move 32 bits with a single variable or constant.
Pauses can get really long, using longs.
Of course, loop commands like For..Next, Repeat..Until and While..Wend can also use a long variable.
Then there are the Lookdown2 and Lookup2 commands that can now search for and return very large numbers.