Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

math - Converting a decimal to a mixed-radix (base) number

How do you convert a decimal number to mixed radix notation?

I guess that given an input of an array of each of the bases, and the decimal number, it should output an array of the values of each column.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Pseudocode:

bases = [24, 60, 60]
input = 86462                       #One day, 1 minute, 2 seconds
output = []

for base in reverse(bases)
    output.prepend(input mod base)
    input = input div base          #div is integer division (round down)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...