o add dex x hex x binary converter

This commit is contained in:
optixx 2009-04-20 21:59:50 +02:00
parent e4364eedb1
commit 6508530384

26
scripts/b.py Executable file
View File

@ -0,0 +1,26 @@
#!/usr/bin/python
import sys
try:
if 'x' in sys.argv[1] or 'X' in sys.argv[1]:
v = int(sys.argv[1],16)
else:
v = int(sys.argv[1])
except:
print "%s NUM" % sys.argv[0]
sys.exit(-1)
bits = 32
sys.stdout.write("0b")
for i in range(bits-1,-1,-1):
s = 1<<i
if v & s:
sys.stdout.write("1")
else:
sys.stdout.write("0")
if i and not i%8:
sys.stdout.write(" ")
print
print "0x%x"% v
print v