RESEARCHUT -- Minds With Innovations
RESEARCHUT
Minds With Innovations

RESEARCHUT - minds with innovations

This site has been archived. The new interface is: HERE

iprint - Andrew "Tridge" Tridgell's iprint in Python

Sunday 05 February 2006 at 5:33 pm. Used tags: , , , , , ,

Following code does the same thing that Tridge's iprint.c does. :-)
#!/usr/bin/env python
import sys
"iprint - Andrew \"Tridge\" Tridgell's iprint in Python"
def toBinary(dec):
"""
This function does the coversion from integer to binary
"""
    bin = ''
    while dec:
        bin = (dec % 2 and '1' or '0') + bin
        dec = long(dec/2)
    return bin or '0'
 
x = 1
text = ''
while len(sys.argv) > 1 and x < len(sys.argv):
    text += sys.argv[x]
    x += 1
 
for x in text:
    print ord(x), "\t", hex(ord(x)), "\t", oct(ord(x)), "\t", toBinary(ord(x)), "\t", x
    print "\n"

No comments



(optional field)
(optional field)
Sorry for the trouble but to prevent spam I require you to answer this silly question.

Comment moderation is enabled on this site. This means that your comment will not be visible until it has been approved by an editor.

Remember personal info?
Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.