How to convert filled string to integer while keeping padding?

I followed a great example in Python: The best way to put zeros in a string is (4), but now I need to turn this filled string into a filled integer.

I tried:

   list_padded=['0001101', '1100101', '0011011', '0011011', '1101111',
      '0000001', '1110111',  1101111', '0111001', '0011011',
      '0011001'] # My padded sting list. 

   int_list=[int(x) for x in list_padded] # convert the string to an INT

But I get a list of integers without padding.

Appreciate any direction or suggestions.

Thanks a lot Jack

Edit: Having studied the revelation that integers are not being filled, I think a little differently, however it would be nice to explain more:

I am working on a basic encryption exercise in a book. He gave me a pseduocode list to work with - get the encryption line 1-127 and message, convert both to binary, separate 0b and pad with zeros. However, he wants me to leave WITHOUT CHORUS! I got this line at a time, but now it happens (where the problem starts):

  • Perform a manual XOR operation and add a binary 7-bit result to the encrypted string
  • Convert each binary bit of the message character and key to an integer
  • Perform an XOR operation for these two bits
  • Convert literal True and False to binary bit and append to output

I love to use the XOR operation, but I'm afraid I'm not going to learn what I need.

-J

+3
source share
4

. / , , .

+9

, , , :

int_list = [(int(x), len(x)) for x in list_padded]

, , . .

+4

:

"{0:b}".format(4).zfill(8)

XOR :

def xor(x, y):
    return (~x & y) | (~y & x)

def bool_xor(x, y):
    return ((not x) and y) or ((not y) and x)

, : http://en.wikipedia.org/wiki/Functional_completeness

0

Since the type INT is a number, it will be stored without leading zeros. Why do you want to save 675 as 00675? This is pointless in the field of integers. I would suggest storing integers as integers, and then apply only the registration when you access them and print them (or what you do with them)

-1
source

Source: https://habr.com/ru/post/1754308/


All Articles