I was wondering how to do effective bit manipulation in Python and there is no 0bbbbb and yet there is 0xhhhh entry. I looked through wiki and saw that there is discussion of how to represent numbers and 123(hex) was mentioned as well as showing numbers with their base like "1016 = 16" or "102 = 2". This implies that everybody thinks in decimal normally, though some programmers might be exceptions to that.
It seems the best approach I have seen so far for Python is this
$ python binary_number = '110001' print int(binary_number,2) print chr(int(binary_number,2)) print "%x" % (int(binary_number,2)) the answers are 49,1,31 ASCII "1" is 49 decimal, 31 hex exit() $ exit
It makes no real difference, it just makes the transition points between doing shell script, C, assembly, Python, or Perl, a little confusing to reorient the mind set to use if-fi, if-else, tabbing, int foo(int foos){return 0;} and any number of other things. If it were too easy it wouldn't be as much fun as it always contains an element of risk that I will enter the wrong method and have a dramatic
... exit() screwup. The exit() is one of those things as I was using Python to confirm something in another window and focus was on this. Lucky that blog software doesn't take serial input as commands, otherwise I might have shut down Google.
0 comments:
Post a Comment