Page 1 of 1

What is 'mod' in PB?

Posted: Sun Jul 30, 2006 1:21 am
by ..::Origin::..
Mod is used in another language, as said in its manual:
The mod operator returns the remainder obtained by dividing its operands. In other words, x mod y = x - (x div y) * y.
Can anyone show me how this is done in PB? I'm trying to convert RC4 encryption from another language to PureBasic.

Posted: Sun Jul 30, 2006 1:26 am
by Pupil
mod in PB is the operator '%' , use like this: '10 % 2'..

Posted: Sun Jul 30, 2006 1:27 am
by srod
Use %.

E.g. 5 % 3 will equal 2.

**EDIT - too slow! :D

Posted: Sun Jul 30, 2006 1:40 am
by ..::Origin::..
Awesome, Thanks, One last question, i have no clues for this, But what is '^' in PureBasic?

For example

Code: Select all

Chr(Asc(Mid(Str$,i+1,i+2)) ^ k)

Posted: Sun Jul 30, 2006 1:43 am
by netmaestro
Pow(5, 2) would return 25, or 5 raised to the 2nd power.

Posted: Sun Jul 30, 2006 1:48 am
by Flype
pupil, srod : too slow :D

Posted: Sun Jul 30, 2006 1:51 am
by Pupil
Flype wrote:pupil, srod : too slow :D
+Flype: too slow and OT!! ;)

Posted: Sun Jul 30, 2006 2:02 am
by ..::Origin::..
Lol, awesome.. Slow-pokes. Thanks for the help, this may be going off topic now, HOPEFULLY the last question, But whats wrong with:

Code: Select all

BoxRC4(i) = BoxRC4(j) 
The error is:

Array Index out of bounds.

What would be the reason causing this?

Posted: Sun Jul 30, 2006 2:16 am
by Dreglor
assuming that "BoxRC4" is a Array either "i" or "j" are outside the specified Range
Ex:

Code: Select all

Dim BoxRC4(10)

BoxRC4(10) = BoxRC4(11) ;<- 11 is error 10 is ok
check your loops

Posted: Sun Jul 30, 2006 2:16 am
by Dare
Either i or j has a value outside of the array dimensions.

Eg:

Code: Select all

Dim Arr(10)

Arr(99) = Arr(2763)
Do a Debug i and a Debug j just before the assignment to see what the values are.


Edit: * joins the slowpokes in the peanut gallery *

Posted: Sun Jul 30, 2006 2:33 am
by ..::Origin::..
Nevermind.

Re: What is 'mod' in PB?

Posted: Sun Jul 30, 2006 2:38 am
by Phoenix
..::Origin::.. wrote:I'm trying to convert RC4 encryption from another language to PureBasic.
Why reinvent the wheel???? Do a search: http://www.purebasic.fr/english/viewtopic.php?t=6905