목록2진수 (1)
without haste but without rest
[python] 10진수 -> 2진수 변환, 2진수 -> 10진수 변환
10진수 -> 2진수 def to_binary(number): answer = '' value = number while value > 1: mod = value % 2 value = value // 2 answer += str(mod) answer += str(value) return answer[::-1] 2진수 -> 10진수 def to_decimal(number): answer = 0 pivot = 1 for n in str(number)[::-1]: if n == '1': ans += int(n)*pivot pivot *= 2 return answer 10진수 -> N진법 변환 def trans(number, N): answer = '' value = int(number) while value ..
ProgrammingLanguage/Python
2021. 7. 22. 15:17