bruteforce version

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
let hexchar_to_int = function
    | x when x >= '0' && x <= '9' -> int x - int '0'
    | x when x >= 'A' && x <= 'F' -> int x - int 'A' + 10
    | _ -> 0

let hex_to_int(xs : string) : bigint = 
    let mutable res = 0I in 
    for c in xs do 
        res <- res * 16I + (new bigint(hexchar_to_int c)) 
        done;
    res

//    Console.WriteLine(hex_to_int("A0"));
//    Console.WriteLine(hex_to_int("10000"));
//    Console.WriteLine(hex_to_int("BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"));
By on 12/29/2008 10:36 AM ()

Thank you for answer. It isn't very nice solution, but anyway I will use it on some places where It is not up to me how will number looks.Thanks.

By on 12/29/2008 11:59 AM ()

Well, I will have to use some another class to work with bigint, because F# BigInteger is completly useless :( It doesn't support ModPow and so on. It doesn't have even bit operators so I can't write my own ModPow...If any developer from F# team read this so please fix this issue...I will try use BigInteger from IronPython - [link:trac.geekisp.com] It looks very well :) but F# solution would be better :(

By on 12/30/2008 2:26 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper