cosmopolitan/tool/scripts/pb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
310 B
Text
Raw Normal View History

#!/bin/sh
exec python -c "
# -*- coding: utf-8 -*-
import sys
from math import *
x = $*
s = x < 0
x = abs(x)
b = str(bin(x))[2:].replace('L', '')
n = len(b)
if n <= 8: n = 8
elif n <= 16: n = 16
elif n <= 32: n = 32
elif n <= 64: n = 64
sys.stdout.write(('%%s0b%%0%dd' % n) % ('-' if s else '', int(b)))
"