fork download
  1. def hitungNomorBit(angka, nomorBit):
  2. biner = []
  3.  
  4. if angka == 0:
  5. if nomorBit == 0:
  6. return 0
  7. else:
  8. return None # null
  9.  
  10. while angka > 0:
  11. sisa = angka % 2
  12. biner.append(sisa)
  13. angka = angka // 2
  14.  
  15.  
  16. if nomorBit >= len(biner):
  17. return None
  18.  
  19. return biner[nomorBit]
  20.  
  21.  
  22. print(hitungNomorBit(13, 0))
  23. print(hitungNomorBit(13, 1))
  24. print(hitungNomorBit(13, 2))
  25. print(hitungNomorBit(13, 4))
  26.  
Success #stdin #stdout 0.02s 7244KB
stdin
Standard input is empty
stdout
1
0
1
None