-1

I'm creating a 8-bits number with numpy:

a = numpy.uint8(2)

and сall :

bin(a)

Result : ob10 ,but I want to have a representation where all bits of my numbers filled : 00000010

user4629038
  • 89
  • 1
  • 7
  • Possible duplicate of [Binary representation of float in Python (bits not hex)](http://stackoverflow.com/questions/16444726/binary-representation-of-float-in-python-bits-not-hex) – Jongware May 07 '16 at 10:01

1 Answers1

1

use this function

def getBits(a):
    binary=bin(a)
    zeros_required=8-(len(binary)-2)
    return '0'*zeros_required+binary[2:]
Mitiku
  • 5,337
  • 3
  • 18
  • 35