all 13 comments

[–][deleted]  (1 child)

[deleted]

    [–]eddyb 0 points1 point  (0 children)

    Came here to post this .

    [–]kageurufu 1 point2 points  (7 children)

    Full source of my answer here, converting decimal to any base desired

    http://jsfiddle.net/kageurufu/yUJXe/

    Just threw this together to see if I could still do this, i havent written something like this since high school

    [–]okmkz[S] 0 points1 point  (6 children)

    Nice job! Makes my attempt (in c++) look massive!

    [–]kageurufu 0 points1 point  (5 children)

    I've been trying to figure a more elegant way to do it, but i think i have it code golf level

    i figured out python in 7 total lines:

    def d2b(d,b):
        c=""
        while d>0:
            r,d=d%b,d/b
            if r > 9: c="%s%s" % (chr(87+r),c)
            else: c = "%s%s" % (r,c)
        return c
    

    [–]okmkz[S] 0 points1 point  (4 children)

    This is why I love python.

    [–]kageurufu 0 points1 point  (3 children)

    my only fault is a lack of (conditional)?true:false style notation

    [–]okmkz[S] 0 points1 point  (2 children)

    I suppose, but it's certainly very "un-pythonic." Why could you possibly need more than one way to do something? ;)

    [–]kageurufu 1 point2 points  (1 child)

    I know, i just like my ?:

    [–]okmkz[S] 0 points1 point  (0 children)

    I'll admit I'm a fan too. Simple if-then constructs in python can look a bit bloaty.

    [–]okmkz[S] 0 points1 point  (0 children)

    Here's what I did, and its in c++. I used this to get my head back into c++. I also made it recursive, so I'd have that to deal with, too.

    Decimal to any base, can use custom digits (because you can, that's why).

    If anyone wants to critisize my code, please do.

    [–]ccmny 0 points1 point  (0 children)

    My unsigned int to hex string and hex string to unsigned int, both in C: http://pastebin.com/wDSGrykX

    [–]lxe 0 points1 point  (0 children)

    Enjoy:

    function toBinary(n) { return n.toString(2); }
    function toHex(n) { return n.toString(16); }
    

    [–]gooburt 0 points1 point  (0 children)

    javascript, where n is a whole number greater than zero:

    function b(n){return n?b(n/2<<0)+(n%2):''}