Skip to content

Instantly share code, notes, and snippets.

@dela3499
Last active March 31, 2016 01:22
Show Gist options
  • Save dela3499/17ed394ac4f81d41870f1d9d241e9a8b to your computer and use it in GitHub Desktop.
Save dela3499/17ed394ac4f81d41870f1d9d241e9a8b to your computer and use it in GitHub Desktop.
Pattern of set bits in range of binary numbers
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
x = np.arange(256).astype(np.uint8)
y = np.array(map(lambda x: np.unpackbits([x]).sum(), x))
figsize(10,5)
plt.step(x,y,'k', linewidth = 1)
plt.axis([-2,257,0,8.2])
label('Number', '# set bits', '# set bits for range of numbers')
@dela3499
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment