Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. def main(a):
  2. numbers = {
  3. 10: "A",
  4. 11: "B",
  5. 12: "C",
  6. 13: "D",
  7. 14: "E",
  8. 15: "F"
  9. }
  10. if a >= 0:
  11. return hex(a)[2:].upper()
  12. else:
  13. answer_bin = bin(abs(a))[2:]
  14. if len(answer_bin) % 8 != 0:
  15. answer_bin = "0" * (8 - len(answer_bin) % 8) + answer_bin
  16. answer_bin_inversed = ""
  17. for i in answer_bin:
  18. answer_bin_inversed += str((int(i) + 1) % 2)
  19. return hex(int(answer_bin_inversed, 2) + 1)[2:].upper()
  20.  
  21. print(main(-1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement