[ create a new paste ] login | about

Link: http://codepad.org/4cxPU1vV    [ raw code | output | fork ]

Python, pasted on Jul 27:
steamid = 76561197969130713

def toBinary( decimalNumber ):
    quotient = 1
    remainder = 0
    tmpNum = decimalNumber
    finalNumberList = []
    n = ""
    #e.g. take 14...
    while quotient != 0:
        remainder = decimalNumber % 2 #14 % 2 = 0
        quotient = decimalNumber / 2 #14 / 2 = 7
        decimalNumber = quotient # 7 % 2 = 1 and so on...
        finalNumberList.insert( 0, remainder )
    # Used because all numbers are in a list, i.e. convert to string
    for num in finalNumberList:
        n += str( num )
    return n

def toDecimal( binaryNumber ):
    multiplier = 0
    number = 0
    for el in binaryNumber[ : : -1 ]:
        number += int( el ) * ( 2**multiplier )
        multiplier += 1
    return number

print "SteamID:"
print steamid
print "\n"

print "ToBinary:"
print toBinary(steamid)
print "\n"

print "Get First 32bit, toDecimal ( Expects 31609526 )"
print toDecimal(toBinary(steamid)[-32:])
print "\n"


Output:
1
2
3
4
5
6
7
8
9
10
11
12
SteamID:
76561197969130713


ToBinary:
100010000000000000000000100000000100001110100010011011001


Get First 32bit, toDecimal ( Expects 31609526 )
8864985




Create a new paste based on this one


Comments: