


- #Python serial inwaiting example how to
- #Python serial inwaiting example code
- #Python serial inwaiting example plus
- #Python serial inwaiting example free
#Python serial inwaiting example code
Print "Python tracks the carry bit in machine code and knows the sign." Print "If I was to compliment z add 1 I'd get 4." 8 subtraction by compliment +1 -> negative result" Y = ~19 + 1 # compliment add 1 same as -19 # Let's do this now for a negative result. Z = z & 0xffff to remove carry bit z will = 0 Which Python displays but my program ignores.īelow is in reality 0 with a set carry bit. You will have to check for carry (D16) bit XORed with 0xffff inverting all the bits. 7 -> subtraction by compliment +1 -> 0 or positive result"Ī compliment of a number is simply the number # "z & 0xffff" removes carry bit for display purposes. # check for carry bit (D16) set (1) is positive or zero, Y = ~15 + 1 # invert bits add 1 same as -15 # We compliment the subtrahend and add 1 then add it all together. # What is really going on at the machine level you don't see? Once again carry indicates positive result - but that is hidden. 4 -> subtraction by adding compliment +1"
#Python serial inwaiting example plus
# (all bits inverted) in the subtrahend plus 1. # Subtraction in binary is done by adding the compliment # The compliment function inverts all bits. Result: bit D1 was set while the others are unchanged.

# bitwise XOR inverts bits when XORed with 1: Print "Ex 1a -> bitwise AND -> z = x & Y" Result: bits D0-D3 are all cleared to 0s. # bitwise AND is used for masking out (changing to 0) selected bits: # This helps the student to better picture what is really happening. # I wrote my functions viewNumbers, convBinary to show leading zeros. # Notice the leading zeros were dropped with the Python functions. # Python has functions to convert integers to binary, octal, and hex: # The example below illustrates this and print 7 three times: # Python accepts integers as binary, octal, and hex. # These examples work the same way in C and assembly.įrom convBinary import viewNumbers, convBinary # This can be done from Idle, Geany, or command line # on the command line: python examples.py # or this module can be run as a whole in Linux # Each of these examples can be done from a terminal # Having a scrolling type terminal program # x, y, and z and study the bit patterns.
#Python serial inwaiting example free
# This uses examples - feel free to change variables # We will use bitwise AND, OR, XOR, compliment, # By Lewis Loflin - Requires convBinary.py
#Python serial inwaiting example how to
How to set this up is on my webpage Programming the PC Printer Port in Python

To use the printer port one must setup a module (modified by me) pyparallel. It requires the use of convBinary.py and both can be downloaded and saved. These are working examples of bit operations under Python and runs under Linux. The examples are applicable to other languages such as C and assembly. This is part of my tutorial on using the PC printer port to control hardware.
