D-9 기초 수학

박초화·2024년 1월 11일
0
  1. 파이썬 제공 진법 변환 함수
# 10진수 -> X진수
print('2진수: {}'.format(bin(dNum)))
print('8진수: {}'.format(oct(dNum)))
print('16진수: {}'.format(hex(dNum)))


print('Type of bin(dNum): {}'.format(type(bin(dNum)))) -> 문자열
print('Type of oct(dNum): {}'.format(type(oct(dNum))))
print('Type of oct(dNum): {}'.format(type(hex(dNum))))


# 10진수 -> X진수(format()함수 이용)
print('2진수: {}'.format(format(dNum, '#b')))
print('8진수: {}'.format(format(dNum, '#o')))
print('16진수: {}'.format(format(dNum, '#x')))

print('Type of bin(dNum): {}'.format(type(format(dNum, '#b'))))
print('Type of oct(dNum): {}'.format(type(format(dNum, '#o'))))
print('Type of oct(dNum): {}'.format(type(format(dNum, '#x'))))

print('2진수: {0:#b}, 8진수: {0:#o}, 16진수: {0:#x}'.format(dNum, dNum, dNum))
print('2진수: {0:#b}, 8진수: {0:#o}, 16진수: {0:#x}'.format(dNum))

print('2진수: {}'.format(format(dNum, 'b')))
print('8진수: {}'.format(format(dNum, 'o')))
print('16진수: {}'.format(format(dNum, 'x')))

print('Type of bin(dNum): {}'.format(type(format(dNum, 'b'))))
print('Type of oct(dNum): {}'.format(type(format(dNum, 'o'))))
print('Type of oct(dNum): {}'.format(type(format(dNum, 'x'))))

print('2진수: {0:b}, 8진수: {0:o}, 16진수: {0:x}'.format(dNum))


# X진수 -> 10진수
print('2진수(0b11110) -> 10진수({})'.format(int('0b11110', 2)))
print('8진수(0o36) -> 10진수({})'.format(int('0o36', 8)))
print('16진수(0x1e) -> 10진수({})'.format(int('0x1e', 16)))
  1. 등차수열
  • 일반항 구하는 공식
    : an = a1 + (n - 1)*d

  • 등차 수열의 합
    : Sn = n(a1+an)/2

profile
도전적인 개발자

0개의 댓글

관련 채용 정보