473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

division by 7 efficiently ???

How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.

Feb 1 '07 #1
31 2518
kr***********@gmail.com writes:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
Erm, sounds like a homework problem... suggestion: think of how many
input bits you have, then check the accuracy of the obvious
approximations until you reach one that's precise enough.
Feb 1 '07 #2
kr***********@gmail.com writes:
How to divide a number by 7 efficiently without using - or /
operator. We can use the bit operators. I was thinking about bit
shift operator but I don't know the correct answer.
I think you are asking for help on a homework assignment in violation
of collusion and plagiarism rules of your educational institution, and
I claim my ten zorkmids.

Please use the resources made available to you in your course of
study; this almost certainly does not include having people on
discussion forums answer the homework for you.

--
\ "I like to go to art museums and name the untitled paintings. |
`\ 'Boy With Pail'. 'Kitten On Fire'." -- Steven Wright |
_o__) |
Ben Finney

Feb 1 '07 #3
On Wed, 31 Jan 2007 18:42:54 -0800, krypto.wizard wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
I'd be surprised if there was a trick for dividing by seven efficiently...
it is one of the "difficult" cases. See:

http://www.bitwisemag.com/copy/wilf/wilf5.html

for a discussion.

But even if there is some nifty algorithm for efficiently dividing by
seven using bit operators, I don't expect it will work efficiently in
Python. The overhead of using objects will probably outweigh any saving
you might get by using magic tricks, so you should just use division.

It is like using the XOR trick for swapping integers: there's just no
point in doing it in Python except as a trick, because it is slower than
just swapping them:
>>timeit.Timer("x = x^y; y = x^y; x= x^y", "x, y = 1, 2").repeat()
[0.88827300071716309, 0.85192012786865234, 0.81278204917907715]
>>timeit.Timer("x, y = y, x", "x, y = 1, 2").repeat()
[0.71292495727539062, 0.65545105934143066, 0.68413901329040527]
--
Steven D'Aprano

Feb 1 '07 #4
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.

Thanks,
On Jan 31, 10:01 pm, Ben Finney <bignose+hates-s...@benfinney.id.au>
wrote:
krypto.wiz...@gmail.com writes:
How to divide a number by 7 efficiently without using - or /
operator. We can use the bit operators. I was thinking about bit
shift operator but I don't know the correct answer.

I think you are asking for help on a homework assignment in violation
of collusion and plagiarism rules of your educational institution, and
I claim my ten zorkmids.

Please use the resources made available to you in your course of
study; this almost certainly does not include having people on
discussion forums answer the homework for you.

--
\ "I like to go to art museums and name the untitled paintings. |
`\ 'Boy With Pail'. 'Kitten On Fire'." -- Steven Wright |
_o__) |
Ben Finney

Feb 1 '07 #5
kr***********@gmail.com wrote:
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.
The answer to that question is that the fastest way to divide
by 7 is to use the divide instruction. You'd have to go down
to a really old 8-bit microprocessor like the Intel 8051 to
find something where bit-twiddling like that pays off.

And no way would this be a win in Python, which is
interpreted.

John Nagle
Feb 1 '07 #6
On Feb 1, 2:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
>>int.__div__(14,2)
7
>>>
Not a minus or division operator in sight ;-)

- Paddy.

Feb 1 '07 #7
"Paddy" <pa*******@netscape.netwrites:
On Feb 1, 2:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
>int.__div__(14,2)
7
>>

Not a minus or division operator in sight ;-)
I salute you, sir. That's the perfect answer to the boneheaded
constraints of the problem :-)

--
\ "What I resent is that the range of your vision should be the |
`\ limit of my action." -- Henry James |
_o__) |
Ben Finney

Feb 1 '07 #8
On Jan 31, 11:36 pm, "Paddy" <paddy3...@netscape.netwrote:
On Feb 1, 2:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
>int.__div__(14,2)
7

Not a minus or division operator in sight ;-)

- Paddy.
Now I'm confused - was the OP trying to divide by 7 or 2?

-- Paul

Feb 1 '07 #9
On Feb 1, 2:36 pm, John Nagle <n...@animats.comwrote:
krypto.wiz...@gmail.com wrote:
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.

The answer to that question is that the fastest way to divide
by 7 is to use the divide instruction. You'd have to go down
to a really old 8-bit microprocessor like the Intel 8051 to
find something where bit-twiddling like that pays off.
Perhaps not that far back. Google "Granlund Montgomery". The technique
got built into gcc.
And no way would this be a win in Python, which is
interpreted.
Agreed.


Feb 1 '07 #10
In <11*********************@a34g2000cwb.googlegroups. com>, Paul McGuire
wrote:
On Jan 31, 11:36 pm, "Paddy" <paddy3...@netscape.netwrote:
>On Feb 1, 2:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
int.__div__(14,2)
7

Not a minus or division operator in sight ;-)

- Paddy.

Now I'm confused - was the OP trying to divide by 7 or 2?
I read it as divide by 7. And the `int.__div__()` Method limits this
somehow -- a more polymorphic approach would be::

import operator
operator.div(14, 7)

:-)

Ciao,
Marc 'BlackJack' Rintsch
Feb 1 '07 #11
This is maybe not so efficient :) but it implements integer division
by 7 for positive integers without - and /.

def div2(num):
return num >1

def div4(num):
return num >2

def div8(num):
return num >3

def mul2(num):
return num << 1

def mul4(num):
return num << 2

def mul7(num):
return mul4(num) + mul2(num) + num

def div7_help(num, lo, hi):
avg = div2(lo + hi)

if avg == lo or avg == hi:
if mul7(hi) == num:
return hi
return lo

avg7 = mul7(avg)
if avg7 num:
return div7_help(num, lo, avg)
elif avg7 < num:
return div7_help(num, avg, hi)
return avg

def div7(num):
lo = div8(num)
hi = div4(num)

return div7_help(num, lo, hi)

for nr in range(0, 20000):
#print "%d // 7 = %d" % (nr, nr // 7)
#print "div7(%d) = %d" % (nr, div7(nr))
assert nr // 7 == div7(nr)

A somewhat better approach is to convert the recursion to an
interative method. But that is.. um.. left as an exercise.

--
mvh Björn
Feb 1 '07 #12
On Feb 1, 3:13 am, krypto.wiz...@gmail.com wrote:
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.
In that case, observer that a/b == a * (1/b), and if b is constant you
can compute (1/b) in advance. Since the problem was set by game
programmers I'd hazard that they are OK with relatively limited
precision and the answer that they were looking for was:
a = (b * 04444444445L) >32
Note that the constant there is in octal.

Nicko

Feb 1 '07 #13
The correct answer as told to me by a person is

(N>>3) + ((N-7*(N>>3))>>3)
The above term always gives division by 7

Feb 1 '07 #14
"Krypto" <kr***********@gmail.comwrites:
The correct answer as told to me by a person is

(N>>3) + ((N-7*(N>>3))>>3)
The above term always gives division by 7
Well, not exactly:

[GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>def f(N): return (N>>3) + ((N-7*(N>>3))>>3)
...
>>f(7)
0
>>f(70)
9
>>f(700)
98
Feb 1 '07 #15

MichaelI think it is off by 1 in small numbers, off by a little more
Michaelwith large numbers:
...

Sorta makes you think using the DIV instruction in the CPU is the way to
go. ;-)

Skip
Feb 1 '07 #16
In <11**********************@a75g2000cwd.googlegroups .com>, Krypto wrote:
The correct answer as told to me by a person is

(N>>3) + ((N-7*(N>>3))>>3)
How could it be correct if it uses `-`? You ruled out `-` and `/` in your
first post.

Ciao,
Marc 'BlackJack' Rintsch
Feb 1 '07 #17
On Feb 1, 3:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.
It´s quiet simple. x == 8*(x/8) + x%8, so x == 7*(x/8) + (x/8 + x%8)
x/8 == x>>3, x%8 == x&7
And there you have it, function rounds upwards for numbers not
divisible by 7. Gotta change int(x>0) to int(x>3) to round normally,
or int(x>6) to round downwards.

def d7(x):
if(x>>3 == 0): return int(x>0)
return (x>>3)+d7((x>>3)+(x&7))

Feb 2 '07 #18
On 2007-02-01, Michael Yanowitz <m.********@kearfott.comwrote:
I think it is off by 1 in small numbers, off by a little more with large
numbers:
>>>def div7 (N):
... return (N>>3) + ((N-7*(N>>3))>>3)
...
>>>div7 (70)
9
>>>div7 (77)
10
>>>div7 (700)
98
>>>div7 (7)
0
>>>div7 (10)
1
>>>div7 (14)
1
>>>div7 (21)
2
>>>div7 (700)
98
>>>div7 (7000)
984
Heh, heh. That's reminding of the "fabulous" O(n) Dropsort
algorithm I saw linked from Effbot's blog.

--
Neil Cerutti
I'm tired of hearing about money, money, money, money, money. I just want to
play the game, drink Pepsi, wear Reebok. --Shaquille O'Neal
Feb 2 '07 #19
On Feb 2, 11:03 pm, "Bart Ogryczak" <B.Ogryc...@gmail.comwrote:
On Feb 1, 3:42 am, krypto.wiz...@gmail.com wrote:
How to divide a number by 7 efficiently without using - or / operator.
We can use the bit operators. I was thinking about bit shift operator
but I don't know the correct answer.

It´s quiet simple. x == 8*(x/8) + x%8, so x == 7*(x/8) + (x/8 + x%8)
x/8 == x>>3, x%8 == x&7
And there you have it, function rounds upwards for numbers not
divisible by 7. Gotta change int(x>0) to int(x>3) to round normally,
or int(x>6) to round downwards.

def d7(x):
if(x>>3 == 0): return int(x>0)
return (x>>3)+d7((x>>3)+(x&7))
I doubt that a recursive function call (even a tail-recursive one)
comes near what the OP and his interrogators mean by "efficiently".

Nicko has already given the answer for the case where a 31-bit non-
negative dividend is required. Here are some examples of the technique
for cases where smaller numbers are found e.g. in date arithmetic.

def div7a(N):
assert 0 <= N <= 684
r = (N << 3) + N
r = (r << 3) + N
r = (r << 2) + N
r >>= 11
return r

def div7b(N):
assert 0 <= N <= 13109
r = (N << 3) + N
r = (r << 3) + N
r = (r << 3) + N
r = (r << 3) + N
r = (r << 1) + N
r >>= 16
return r

What's going on there? Well, using the first example, (2 ** 11) // 7
and rounded to the higher integer is 293. So 293 / 2048 is an
approximation to 1 / 7. Dividing by 2048 is a doddle. The shift-left-
add stuff is doing the multiplication by 293, unrolled loop, one cycle
per line when implemented as a SHLnADD instruction from the HP PA-RISC
architecture. Unsigned division otherwise would take 32 DS (divide
step) instructions.

FWIW, gcc emits code for the Intel IA32 architecture that gloriously
"misuses" the LEAL instruction to get the same reg1 = (reg2 << n) +
reg3 effect.

Any relevance to this newsgroup? Yes, there's a lot of pre-computation
involved there. Python is an excellent language for debugging such
stuff and generating include files for a production code.

Cheers,
John

Feb 2 '07 #20
On 31 Jan 2007 19:13:14 -0800, kr***********@gmail.com
<kr***********@gmail.comwrote:
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.
I think this works:
>>def div7 (N):
.... return ((N * 9362) >16) + 1
....
>>div7(7)
1
>>div7(14)
2
>>div7(700)
100
>>div7(70000)
10000

The coolest part about that (whether it works or not) is that it's my
first Python program. I wrote it in C first and had to figure out how
to convert it. :)

Jesse
Feb 2 '07 #21
On Feb 3, 2:31 am, "Jesse Chounard" <jessechoun...@gmail.comwrote:
On 31 Jan 2007 19:13:14 -0800, krypto.wiz...@gmail.com

<krypto.wiz...@gmail.comwrote:
Its not an homework. I appeared for EA sports interview last month. I
was asked this question and I got it wrong. I have already fidlled
around with the answer but I don't know the correct reasoning behind
it.

I think this works:
You think wrongly. Inspection reveals that it is obviously incorrect
for N == 0. Trivial testing reveals that it is wrong for about 6 out
of every 7 cases.
>
>def div7 (N):

... return ((N * 9362) >16) + 1
...>>div7(7)
1
>div7(14)
2
>div7(700)
100
>div7(70000)

10000

The coolest part about that (whether it works or not) is that it's my
first Python program. I wrote it in C first and had to figure out how
to convert it. :)
Try testing algorithms with a pencil on the back of an envelope first.

The uncoolest part about that is that your test data is horribly
deficient:
>>for N in xrange(0, 23):
.... a = ((N * 9362) >16) + 1
.... e = N // 7
.... print N, a, e, a == e
....
0 1 0 False
1 1 0 False
2 1 0 False
3 1 0 False
4 1 0 False
5 1 0 False
6 1 0 False
7 1 1 True
8 2 1 False
9 2 1 False
10 2 1 False
11 2 1 False
12 2 1 False
13 2 1 False
14 2 2 True
15 3 2 False
16 3 2 False
17 3 2 False
18 3 2 False
19 3 2 False
20 3 2 False
21 3 3 True
22 4 3 False

HTH,
John

Feb 2 '07 #22
On Feb 1, 2:00 pm, "Nicko" <use...@nicko.orgwrote:
precision and the answer that they were looking for was:
a = (b * 04444444445L) >32
Note that the constant there is in octal.
04444444445L? Shouldn´t it be 04444444444?
Or more generally,
const = (1<<bitPrecision)/7
a = (b * const)>>bitPrecision
Feb 2 '07 #23
On Feb 2, 4:21 pm, "Bart Ogryczak" <B.Ogryc...@gmail.comwrote:
On Feb 1, 2:00 pm, "Nicko" <use...@nicko.orgwrote:
precision and the answer that they were looking for was:
a = (b * 04444444445L) >32
Note that the constant there is in octal.

04444444445L? Shouldn´t it be 04444444444?
Or more generally,
const = (1<<bitPrecision)/7
a = (b * const)>>bitPrecision
It's to do with rounding. What you actually need is
ceiling((1<<bitPrecision)/7), rather than floor((1<<bitPrecision)/7).

Nicko

Feb 2 '07 #24
On Feb 1, 8:25 pm, "Krypto" <krypto.wiz...@gmail.comwrote:
The correct answer as told to me by a person is

(N>>3) + ((N-7*(N>>3))>>3)

The above term always gives division by 7
No it doesn't. The above term tends towards N * (9/64), with some
significant rounding errors. 9/64 is a fairly poor (6 bit)
approximation of 1/7 but the principle is the same as the solution I
proposed above.

Nicko

Feb 2 '07 #25
On Feb 1, 8:25 pm, "Krypto" <krypto.wiz...@gmail.comwrote:
The correct answer as told to me by a person is
(N>>3) + ((N-7*(N>>3))>>3)
The above term always gives division by 7
Does anybody else notice that this breaks the spirit of the problem
(regardless of it's accuracy)? 'N-7' uses the subtraction operator,
and is thus an invalid solution for the original question.

Build a recursive function, which uses two arbitrary numbers, say 1
and 100. Check each, times 7, and make sure that your target number,
N, is between them. Increase or decrease your arbitrary numbers as
appropriate. Now pick a random number between those two numbers, and
check it. Figure out which two the answer is between, and then check a
random number in that subset. Continue this, and you will drill down
to the correct answer, by using only *, +, >, and <.

I'll bet money that since this was a programming interview, that it
wasn't a check of your knowledge of obscure formulas, but rather a
check of your lateral thinking and knowledge of programming.

~G

Feb 6 '07 #26
On Feb 6, 3:29 pm, garri...@gmail.com wrote:
On Feb 1, 8:25 pm, "Krypto" <krypto.wiz...@gmail.comwrote:
The correct answer as told to me by a person is
(N>>3) + ((N-7*(N>>3))>>3)
The above term always gives division by 7

Does anybody else notice that this breaks the spirit of the problem
(regardless of it's accuracy)? 'N-7' uses the subtraction operator,
and is thus an invalid solution for the original question.
[snip]
Instead of subtraction you can use complement-and-add: N + ~7 + 1
(that's a tilde '~' not a minus '-').

Feb 6 '07 #27
On Feb 7, 2:29 am, garri...@gmail.com wrote:
On Feb 1, 8:25 pm, "Krypto" <krypto.wiz...@gmail.comwrote:
The correct answer as told to me by a person is
(N>>3) + ((N-7*(N>>3))>>3)
The above term always gives division by 7

Does anybody else notice that this breaks the spirit of the problem
(regardless of it's accuracy)? 'N-7' uses the subtraction operator,
and is thus an invalid solution for the original question.

Build a recursive function, which uses two arbitrary numbers, say 1
and 100.
Recursive? Bzzzt!
Check each, times 7, and make sure that your target number,
N, is between them. Increase or decrease your arbitrary numbers as
appropriate. Now pick a random number between those two numbers, and
check it. Figure out which two the answer is between, and then check a
random number in that subset
Might it not be better to halve the interval at each iteration instead
of calling a random number function? mid = (lo + hi) >1 looks
permitted and cheap to me. Also you don't run the risk of it taking a
very high number of iterations to get a result.
>. Continue this, and you will drill down
to the correct answer, by using only *, +, >, and <.

I'll bet money that since this was a programming interview, that it
wasn't a check of your knowledge of obscure formulas, but rather a
check of your lateral thinking and knowledge of programming.

~G
Did you notice the important word *efficiently* in line 1 of the spec?
Even after ripping out recursion and random numbers, your proposed
solution is still way off the pace.

Cheers,
John

Feb 7 '07 #28
On Feb 6, 4:54 pm, "John Machin" <sjmac...@lexicon.netwrote:
Recursive? Bzzzt!
I woudl be happy to hear your alternative, which doesn't depend on
language specific tricks. Thus far, all you have suggested is using an
alternative form of the division function, which I would consider to
be outside the spirit of the question (though I have been wrong many
times before).
Might it not be better to halve the interval at each iteration instead
of calling a random number function? mid = (lo + hi) >1 looks
permitted and cheap to me. Also you don't run the risk of it taking a
very high number of iterations to get a result.
I had considered this, but to halve, you need to divide by 2. Using
random, while potentially increasing the number of iterations, removes
the dependency of language tricks and division.
Did you notice the important word *efficiently* in line 1 of the spec?
Even after ripping out recursion and random numbers, your proposed
solution is still way off the pace.
Again, I look forward to reading your solution.

Respectfully, G.

Feb 7 '07 #29
On Feb 7, 11:05 am, garri...@gmail.com wrote:
On Feb 6, 4:54 pm, "John Machin" <sjmac...@lexicon.netwrote:
Recursive? Bzzzt!

I woudl be happy to hear your alternative, which doesn't depend on
language specific tricks. Thus far, all you have suggested is using an
alternative form of the division function,
Huh? Thus far (in this post) all I've said is (in effect) that IMHO
mentioning recursion is just cause for termination of job interview.
which I would consider to
be outside the spirit of the question (though I have been wrong many
times before).
Might it not be better to halve the interval at each iteration instead
of calling a random number function? mid = (lo + hi) >1 looks
permitted and cheap to me. Also you don't run the risk of it taking a
very high number of iterations to get a result.

I had considered this, but to halve, you need to divide by 2. Using
random, while potentially increasing the number of iterations, removes
the dependency of language tricks and division.
"Potentially increases the number of iterations"? Sorry, the interview
for marketing manager is across the hall. For example if your N must
fit in 16 bits, you could end up with O(2**16) iterations. This may
not show up in acceptance testing. And each iteration involves calling
a random number function. A binary search has a guaranteed upper limit
of O(16). Let's get this in contect: the traditional "long division"
approach takes 16 iterations!

Shifting to divide by a power of 2 is not a "language trick". In any
case any compiler that deserves to be used will replace division by a
power of 2 with a shift.
>
Did you notice the important word *efficiently* in line 1 of the spec?
Even after ripping out recursion and random numbers, your proposed
solution is still way off the pace.

Again, I look forward to reading your solution.
Respectfully, read my other posts in this thread.
The correct answer IMHO is "Semi-decent compilers like gcc will do a
good-enough job of dividing an integer by a constant. Only in
situations like a very high-use library routine where the N is known
to be much smaller than 2**wordsize might it be worthwhile to see if a
bit-bashing approach could generate faster code".

Cheers,
John

Feb 7 '07 #30
ga******@gmail.com schreef:
On Feb 6, 4:54 pm, "John Machin" <sjmac...@lexicon.netwrote:
>Recursive? Bzzzt!
Might it not be better to halve the interval at each iteration instead
of calling a random number function? mid = (lo + hi) >1 looks
permitted and cheap to me. Also you don't run the risk of it taking a
very high number of iterations to get a result.

I had considered this, but to halve, you need to divide by 2. Using
random, while potentially increasing the number of iterations, removes
the dependency of language tricks and division.
It's possible to use Fibonacci numbers instead of halving each time;
that requires only addition and subtraction. Unfortunately I forgot
exactly how that works, and I don't have the time to look it up or to
try to reproduce it now. Maybe later.

AFAIK that method is not commonly used since binary computers are very
good at dividing numbers by two, but it would be a good method on
ternary or decimal computers.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Feb 7 '07 #31
Roel Schroeven schreef:
ga******@gmail.com schreef:
>I had considered this, but to halve, you need to divide by 2. Using
random, while potentially increasing the number of iterations, removes
the dependency of language tricks and division.

It's possible to use Fibonacci numbers instead of halving each time;
that requires only addition and subtraction. Unfortunately I forgot
exactly how that works, and I don't have the time to look it up or to
try to reproduce it now. Maybe later.

AFAIK that method is not commonly used since binary computers are very
good at dividing numbers by two, but it would be a good method on
ternary or decimal computers.
Responding to myself since I found an explanation in the obvious place:

http://en.wikipedia.org/wiki/Fibonacci_search_technique

It is meant for search in ordered arrays though; I don't think it can be
adapted for searching in mathematic intervals.

--
If I have been able to see further, it was only because I stood
on the shoulders of giants. -- Isaac Newton

Roel Schroeven
Feb 7 '07 #32

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Darius Fatakia | last post by:
hi, i'm new to MS Visual Studio and C++ but not to C programming in general. i'm trying to divide two integers and get their actual quotient (eg 5/3 = 1.666667 etc). i thought i had type cast...
40
by: fordge | last post by:
we usually use <<n as a cheaper option to multiplication when its factor of 2^n right, even for non 2^n say ix24 ==> ix(16+8) ==> (i<<4)+(i<<3) similarly divison 2^n is >>n
29
by: nessuno | last post by:
I can't find any discussion of this question in this NG. I'd like to implement some variable precision integer arithmetic in C, and do it efficiently. A problem arises with the divide/remainder...
17
by: seb.haase | last post by:
Hi, Is it true that that "Python 3000" is dead ? Honestly I think that e.g. changing 5/2 to be 2.5 (instead of 2) would just break to much code :-( On the otherhand I'm using Python as "Matlab...
2
by: kermit | last post by:
For a long time,, There has been a discussion of trueFor division versus integer division in Python. I myslef prefer that / be used for integer division since almost always, I want the...
13
by: jamesonang | last post by:
Supposed unsigned int(32 bits) is the largest number that computer can represent with a single variable. Now, i have a big integer ( less than 64 bit, but great than 32 bit) . i represent it by...
94
by: krypto.wizard | last post by:
Last month I appeared for an interview with EA sports and they asked me this question. How would you divide a number by 7 without using division operator ? I did by doing a subtraction and...
2
by: Vadim Tropashko | last post by:
http://vadimtropashko.wordpress.com/why-relational-division-is-so-uncommon/
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.