Re: Ensure a variable is divisible by 4

2006-12-05 Thread Jonathan Smith
MRAB wrote: >> if ( x % 4 ) == 0: >> whatever # x is divisible by 4 >> >> modulus is your friend :) >> >> -smithj > > > It's "modulo"; "modulus" is a different operation. > > Wikipedia says "modulus may refer to... %, the modulo operator of various programming languages" http://en.wikip

Re: Ensure a variable is divisible by 4

2006-12-05 Thread MRAB
Jonathan Smith wrote: > > <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > >> I am sure this is a basic math issue, but is there a better way to > >> ensure an int variable is divisible by 4 than by doing the following; > >> > >> x = 111 > >> x = (x /4) * 4 > >> > >> Just seems a

Re: Ensure a variable is divisible by 4

2006-12-05 Thread david brochu jr
CTED]> To: python-list@python.org Date: 5 Dec 2006 11:26:49 -0800 Subject: Re: Ensure a variable is divisible by 4 Paul Rudin wrote: Max M <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] skrev: >> Nick Craig-Wood wrote: >>> [EMAIL PROTECTED] <[EMAIL PROTECTED]>

Re: Ensure a variable is divisible by 4

2006-12-05 Thread John Machin
Paul Rudin wrote: > Max M <[EMAIL PROTECTED]> writes: > > > [EMAIL PROTECTED] skrev: > >> Nick Craig-Wood wrote: > >>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by do

Re: Ensure a variable is divisible by 4

2006-12-05 Thread Paul Rudin
Max M <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] skrev: >> Nick Craig-Wood wrote: >>> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: I am sure this is a basic math issue, but is there a better way to ensure an int variable is divisible by 4 than by doing the following; x

Re: Ensure a variable is divisible by 4

2006-12-05 Thread Max M
[EMAIL PROTECTED] skrev: > Nick Craig-Wood wrote: >> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >>> I am sure this is a basic math issue, but is there a better way to >>> ensure an int variable is divisible by 4 than by doing the following; >>> >>> x = 111 >>> x = (x /4) * 4 X *= 4 ;-) --

Re: Ensure a variable is divisible by 4

2006-12-05 Thread geskerrett
Nick Craig-Wood wrote: > [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > I am sure this is a basic math issue, but is there a better way to > > ensure an int variable is divisible by 4 than by doing the following; > > > > x = 111 > > x = (x /4) * 4 > > You should use // for future compatibilit

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Jonathan Smith
> <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] >> I am sure this is a basic math issue, but is there a better way to >> ensure an int variable is divisible by 4 than by doing the following; >> >> x = 111 >> x = (x /4) * 4 >> >> Just seems a bit clunky to me. if ( x % 4 ) == 0:

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Paul McGuire
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. > All numbers are divisible by 4.

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Grant Edwards
On 2006-12-04, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am sure this is a basic math issue, but is there a better > way to ensure an int variable is divisible by 4 if x & 3: print "not divisible by 4" x &= ~3 print "it is now: x = %d" If you want to round to nearest power of 4 rather

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Nick Craig-Wood
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 You should use // for future compatibility which is guaranteed to be an intege

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Will McGugan
[EMAIL PROTECTED] wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. > Depends what you mean by 'make it divisable'. Do you want to ch

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Tim Chase
> I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. You're right...you'll want to read up on the "modulo" operator: if x % 4 <> 0: pri

Re: Ensure a variable is divisible by 4

2006-12-04 Thread George Sakkis
[EMAIL PROTECTED] wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. if x % 4 == 0: # x is divisible by 4 George -- http://mail.pyt

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Larry Bates
[EMAIL PROTECTED] wrote: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. > Use modulo operator '%' if not x % 4: # # Arrive here if

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Kay Schluehr
[EMAIL PROTECTED] schrieb: > I am sure this is a basic math issue, but is there a better way to > ensure an int variable is divisible by 4 than by doing the following; > > x = 111 > x = (x /4) * 4 > > Just seems a bit clunky to me. Division with rest: >>> x % 4 3 -- http://mail.python.org/m

Ensure a variable is divisible by 4

2006-12-04 Thread geskerrett
I am sure this is a basic math issue, but is there a better way to ensure an int variable is divisible by 4 than by doing the following; x = 111 x = (x /4) * 4 Just seems a bit clunky to me. -- http://mail.python.org/mailman/listinfo/python-list