Usenet.com

www.Usenet.com

Group Index

Comp Thread Archive from Usenet.com

<-- __Chronological__ --> <-- __Thread__ -->

Re: Need hex calculator with square root function



Newbie wrote:
I need a calculator or something to find the square root of a very large hex
number such as
e9087427a4d5a01e8c3a420767651079d0a03adfc19e504627e768299c74d0d1bf10f059ca4c
d805327a90f32be4cbf880a638c07dad0d515770fc58b7835a540b51a1d00b40f80b53cd71b7
75e9af39514f696d988d4f14f6a32ac068eb6da66ff2a5d49a8fb1a47cbf623e59fe7d5163b1
c26d9f7
8000747e463bee0c3.

I have search the internet everyway I know how and come up with nothing. I
am using Virtual calc 2000. I even registered it. It does everything I need
except the hex square root function.  Can anyone point me in the right
direction. I am using Windows ME. Thanks.


Here's output in python (slightly editted), followed by the program that generated it:

Magnitudes: 2.49696889241e+303 4.9969679731e+151 4.9969679731e+151

Original:    E908 7427A4D5 A01E8C3A 42076765 1079D0A0 3ADFC19E 504627E7
68299C74 D0D1BF10 F059CA4C D805327A 90F32BE4 CBF880A6 38C07DAD 0D515770
FC58B783 5A540B51 A1D00B40 F80B53CD 71B775E9 AF39514F 696D988D 4F14F6A3
2AC068EB 6DA66FF2 A5D49A8F B1A47CBF 623E59FE 7D5163B1 C26D9F78 000747E4
63BEE0C3
Lower:     F43F28 2B761B37 D5DC44CD 2D9BFEC1 13B96311 B56845F3 20FC0069
17B65CE5 4D41689A 66DD82F1 529FF514 E071B1FE 78F37167 B4E9DE16 B15CF727
BFEC1F47
Upper:     F43F28 2B761B37 D5DC44CD 2D9BFEC1 13B96311 B56845F3 20FC0069
17B65CE5 4D41689A 66DD82F1 529FF514 E071B1FE 78F37167 B4E9DE16 B15CF727
BFEC1F48
v-l*l:     FB63EF 8D08E071 6E5961D5 8494F298 9EBC16D1 267D8674 BD05CA9C
B8474E3E 85D54E6A E2A6752C B8055132 F5F975AF A9250788 EDC6EBC7 A8D08DCC
C3049B12
h*h-v:     ED1A60 C9E355FE 3D5F27C4 D6A30AE9 88B6AF52 44530571 84F23635
77256B8C 14AD82C9 EB1490B5 ED3A98F6 CAE9EE4D 48C1DB46 7C0CD065 B9E96082
BCD3A37D


-Scott David Daniels [EMAIL PROTECTED]

# ================ bigintsqrt.py ================
import math

hexname = (
    'e9087427a4d5a01e8c3a420767651079d0a03adfc19e504627e76829'
    '9c74d0d1bf10f059ca4cd805327a90f32be4cbf880a638c07dad0d51'
    '5770fc58b7835a540b51a1d00b40f80b53cd71b775e9af39514f696d'
    '988d4f14f6a32ac068eb6da66ff2a5d49a8fb1a47cbf623e59fe7d51'
    '63b1c26d9f78000747e463bee0c3')

value = int(hexname, 16)

def boundsqrt(value):
    """Calculate low and high so that low*low <= value <= high*high."""
    assert isinstance(value, (int, long)) and value > 1
    a = int(math.sqrt(value))  # get a really good guess

    # squeeze ala Newton's method
    differ = a - 1
    while True:
        b = (value // a + a) // 2
        if abs(a - b) >= differ:
            # just got worse
            break
        differ =  abs(a - b)
        a = b

    # a is our best guess.  walk around a bit to find the borders
    high = low = a
    while a * a < value:
        low = a
        high = a = a + 1
    while a * a > value:
        high = a
        low = a = a - 1
    return low, high


def blocked_hex(value, digits): """Format to show hex constants with breaks every so many digits""" numbers = hex(value) # Clean up hex decoration (leading 0x, possible trailing L for long) assert numbers.startswith('0x') numbers = numbers[2:] if numbers.endswith('L'): numbers = numbers[:-1]

    start = numbers[:len(numbers) % digits]
    if len(start) == 0:
        start = numbers[:digits]
    remainder = numbers[len(start):]
    parts = [remainder[n : n + digits]
             for n in range(0,len(remainder), digits)]
    return ' '.join([start] + parts)


if __name__ == '__main__': low, high = boundsqrt(value) assert low * low <= value <= high * high assert low <= high <= low+1 print 'Magnitudes:', float(value), math.sqrt(value), float(low) print 'Original:', blocked_hex(value, 8) print 'Lower:', blocked_hex(low, 8) print 'Upper:', blocked_hex(high, 8) print 'v-l*l:', blocked_hex(value - low*low, 8) print 'h*h-v:', blocked_hex(high*high - value, 8)





<-- __Chronological__ --> <-- __Thread__ -->


Usenet.com



Please check out one of the premium Usenet Newsgroup Service Providers below for access to Usenet.