What is 'mod' in PB?

Just starting out? Need help? Post your questions and find answers here.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

What is 'mod' in PB?

Post 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.
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

mod in PB is the operator '%' , use like this: '10 % 2'..
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Use %.

E.g. 5 % 3 will equal 2.

**EDIT - too slow! :D
I may look like a mule, but I'm not a complete ass.
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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)
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

Pow(5, 2) would return 25, or 5 raised to the 2nd power.
BERESHEIT
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

pupil, srod : too slow :D
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Pupil
Enthusiast
Enthusiast
Posts: 715
Joined: Fri Apr 25, 2003 3:56 pm

Post by Pupil »

Flype wrote:pupil, srod : too slow :D
+Flype: too slow and OT!! ;)
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post 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?
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
Last edited by Dreglor on Sun Jul 30, 2006 2:17 am, edited 2 times in total.
~Dreglor
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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 *
Dare2 cut down to size
..::Origin::..
Enthusiast
Enthusiast
Posts: 125
Joined: Sat Jun 17, 2006 3:15 pm

Post by ..::Origin::.. »

Nevermind.
Last edited by ..::Origin::.. on Sun Jul 30, 2006 12:02 pm, edited 1 time in total.
Phoenix
Enthusiast
Enthusiast
Posts: 141
Joined: Sun Sep 04, 2005 2:25 am

Re: What is 'mod' in PB?

Post 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
Post Reply