0

I'm a beginner here. I'm trying to specify convert decimal to two's complement . Is there a way that I can shorten this code without using this code?

here's my code

inputNum = random.randint(2,100)
angkaku = bin(inputNum)
string_angkaku = '{0:b}'.format(int(inputNum))
number = int(string_angkaku,2)
two_comp = (1)*(255 + 1 - number)
slicing_tc = bin(two_comp)[2:]
George Imerlishvili
  • 1,816
  • 2
  • 12
  • 20
  • Hey there! StackOverflow is a site for coding related problems / challenges. If you want your code to be reviewed or improved, you may want use a different stackexchange website - https://codereview.stackexchange.com/ – HerrAlvé Mar 06 '22 at 13:05
  • yeahh i mean is there any codes to solve my problrm – ramadhan Mar 06 '22 at 13:08
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 06 '22 at 20:15
  • Does this answer your question? [Two's Complement in Python](https://stackoverflow.com/questions/1604464/twos-complement-in-python) – deadshot Mar 07 '22 at 02:26

0 Answers0