Run
decimal = 148
octal = []
while decimal > 0:
r = decimal % 8
octal.append(r)
decimal = decimal // 8
for i in reversed(octal):
print(i, end="")
Output
224
Algorithm ( Method 2 )
- Initialize ocatalNum to 0 and countVal to 1 and the decimal number as n
- Find the remainder when decimal number divided by 8
- Update octal number by octalNum + (remainder * countval)
- Increase countval by countval*10
- Divide decimal number by 8
- Repeat from the second step until the decimal number is zero
num=int(input(“Enter the decimal number “))
sum=0
temp=num
base=1
while(temp):
digit=temp%8
sum+=digit*base
base*=10
temp//=8
print(“The octal value of {} is {}”.format(num,sum))