How do I code a program to perform a logical shift to the left with binary numbers?
arthurabelo (0)

I would like a program that added a zero to the first position in the right, resulting in a shift to the left of the binary number.

You are viewing a single comment. View All
JoshDaBosh (77)

if you're talking about LSHIFT, this would be it in Python:

def lshift(x, am):
        if am >= 8:
                 return "00000000"
        return (x[am:]).ljust(8, "0")

There may be better ways to do it, but that was the quickest way I could think of.