Posted 24 July 2012 - 12:51 PM
So I have the following problem:
I have a number n and then divide this number by 8
let, for example, n = 45
45/8 = 5 r 5 (or 5 & 5/8)
Now I want a way of singling out the 2 parts of this number to give a result like so:
a=5
r=5 (or 5/8(either way isn't a problem because I can just multiply by 8 with the latter))
Let me give 1 last example:
n=59
n/8 = 7 r 3
a=7
r=3
I know how to do everything except for defining 'r' and 'a' separately. Does anyone know how to do this quickly and efficiently without the need for a loop?
————————————————————————————————————————————————
These are some ways I know of making it work: Rounding down n/8 to the nearest integer naming that 'a' then do r = n/8 - 8*a
or
Subtract 1 from n/8 until negative and in the mean time do a=a+1. when negative a=a-1 and r=left over result*8
I have a number n and then divide this number by 8
let, for example, n = 45
45/8 = 5 r 5 (or 5 & 5/8)
Now I want a way of singling out the 2 parts of this number to give a result like so:
a=5
r=5 (or 5/8(either way isn't a problem because I can just multiply by 8 with the latter))
Let me give 1 last example:
n=59
n/8 = 7 r 3
a=7
r=3
I know how to do everything except for defining 'r' and 'a' separately. Does anyone know how to do this quickly and efficiently without the need for a loop?
————————————————————————————————————————————————
These are some ways I know of making it work: Rounding down n/8 to the nearest integer naming that 'a' then do r = n/8 - 8*a
or
Subtract 1 from n/8 until negative and in the mean time do a=a+1. when negative a=a-1 and r=left over result*8