Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Debugging a problem in a Verilog simulation. Needed a convenient way to print values as binary while padded to the bus width.
- class PaddedBinary(object):
- def __init__(self,numbits):
- self.numbits = numbits
- def __call__(self,num):
- s = bin(num)[2:] # trim off the leading '0b'
- s = ('0'*(self.numbits-len(s))) + s
- return s
- padbin68 = PaddedBinary(68)
- print(padbin68(0x4242))
- padbin48 = PaddedBinary(48)
- print(padbin48(0x4242))
- output:
- 00000000000000000000000000000000000000000000000000000100001001000010
- 000000000000000000000000000000000100001001000010
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement