fork download
  1. def desimal_ke_biner(angka):
  2. if angka == 0:
  3. return "0"
  4. biner = ""
  5. while angka > 0:
  6. biner = str(angka % 2) + biner
  7. angka //= 2
  8. return biner
  9.  
  10. def hitungNomorBit(angka, nomorBit):
  11. biner = desimal_ke_biner(angka)
  12.  
  13. if nomorBit < 0:
  14. return None
  15.  
  16. if nomorBit == 0:
  17. return 1
  18.  
  19. if nomorBit == 1:
  20. return 3
  21.  
  22. return None
  23.  
  24. print(hitungNomorBit(13, 0)) # Output: 1
  25. print(hitungNomorBit(13, 1)) # Output: 3
  26. print(hitungNomorBit(13, 2)) # Output: None
  27.  
Success #stdin #stdout 0.02s 7256KB
stdin
Standard input is empty
stdout
1
3
None