Tagged: python Toggle Comment Threads | Keyboard Shortcuts

  • CG 3:32 pm on March 7, 2013 Permalink | Reply
    Tags: bit operations, python   

    Python: Bit Operations 

    Basic bit operations in Python:

    
    #!/usr/bin/python 
    
    a = 60            # 60 = 0011 1100 
    b = 13            # 13 = 0000 1101 
    c = 0
    
    print "a = ", (bin(a)[2:]);
    print "b = ", (bin(b)[2:]);
    
    c = a & b;        # 12 = 0000 1100
    print "a & b = ", (bin(c)[2:]);
    
    c = a | b;        # 61 = 0011 1101 
    print "a | b = ", (bin(c)[2:]);
    
    c = a ^ b;        # 49 = 0011 0001
    print "a ^ b = ", (bin(c)[2:]);
    
    c = ~a;           # -61 = 1100 0011
    print "~a = ", (bin(c)[2:]);
    
    c = a << 2;       # 240 = 1111 0000
    print "a <> 2;       # 15 = 0000 1111
    print "a >> 2 = ", (bin(c)[2:]);
    

    Result:
    Screen shot 2013-03-07 at 3.28.10 PM

    An interesting link about bit operation algorithm implementation in Python is here.

     
  • CG 6:11 pm on November 7, 2012 Permalink | Reply
    Tags: , python   

    Hello World – Python 

    I’m learning Python 😀

    This is the version of Python I’m using:

    And then start using vi to type the code:

    The listing of the code:

    And run the code:

    Ok that’s it for now, I don’t know yet what is so good about Python compared to other languages I’m familiar with (C/C++, Java, Perl). Will post more about this as soon as I learn more about Python.

     
  • CG 12:21 pm on January 28, 2011 Permalink | Reply
    Tags: , python   

    Testing non-composite & composite operation with Python 

    for 299 bit.

    Thx for Fajar Yuliawan for the code. I’m going to use this for testing the multiplier design.

    Useful links:

    1. Phyton for mac can be downloaded here.
    2. Phyton tutorial is here.
     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel