Re: Binary sqrt
From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 11/03/03
- Next message: Bjørge Sæther: "Re: Which database?"
- Previous message: Jud McCranie: "Re: Binary sqrt"
- In reply to: rob wise: "Binary sqrt"
- Next in thread: Dr John Stockton: "Re: Binary sqrt"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 03 Nov 2003 07:43:37 GMT
In article <3fa5a7cf@news.leadingedgeinternet.net.au>, "rob wise"
<rweiz@dcsi.net.au> writes:
>I am wanting to perform a square root to a very long binary number to
>produce its root and any remainder.
>
>I understand it is possible to square root a binary number (in fact any
>number) by working through it from left to right working on pairs bits of
>the number. Much like long division.
>
>Can anyone assist me with a Pascal algorithm to do this please, or a place I
>can find pointers to the procedure.
>
I would think you do it the same as for any number. AFAICR for 54321 with
square root in square brackets ...
1) Mark off in blocks of pairs from right to left.
5'43'21'
2) Starting from left take first block as active-value
5
3) Get largest digit which when squared is less than value from 2
2
4) Put value from 3 as left-most number of Result.
[2]
5) Subtract value in 4 squared from active-value
1
6) Append numbers of next block to remainder
143
7) Multiply Result by 2
4
8) Find largest digit which when appended to value from 7 and that number
multplied by digit, is less than value from 6
3
9) Append that digit to Result and get remainder of (7 appended by 8) * 8 from
6
[23] 143 - (43 * 3) == 14
10) GoTo 6
6) 1421
7) 46
8) 3
9) [233] 1421 - (463 * 3) == 32
6) 3200
7) 466
8) 0
9) [233.0] 466 - 0 == 466
6) 46600
7) 320000
8) 6
9) [233.06] 320000 - (46606 * 6) == 40364
6) 4036400
7) etc etc
SqRt(54321) == 233.0686594
Binary is the same, just remember your binary tables ...
0 x 1 == 0
1 x 1 == 1
2 x 1 == 10
... and when subtracting carry the same as in decimal subtraction.
Alan Lloyd
alanglloyd@aol.com
- Next message: Bjørge Sæther: "Re: Which database?"
- Previous message: Jud McCranie: "Re: Binary sqrt"
- In reply to: rob wise: "Binary sqrt"
- Next in thread: Dr John Stockton: "Re: Binary sqrt"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|