简体   繁体   English

将十进制整数转换为六进制数

[英]Converting a decimal integer to a sexagesimal number

i am looking for simple c code that convert decimal to sexagesimal .Here what i am trying to do. 我正在寻找将十进制转换为六十进制的简单C代码。这是我想做的事情。

t1=13:05
t2=5:30 
t1 minute=13*60+05=785
t2 in minute=5*60+30=330
t1-t2=455minute
time diff=455/60=7 hour 58 minute ("this wrong consideration since value in decimal");
but expected is 7 hour 35 minute 

使用整数除法获得整小时数,然后取模以获取整数或分钟数。

You are basically asking how to convert a number from the decimal base to another base, ie 60, if I understand you correctly. 您基本上是在问,如果我正确理解,如何将数字从十进制转换为另一个基数,即60。 I think that a general algorithm will help you get the general idea behind your question, try this http://www.cs.trincoll.edu/~ram/cpsc110/inclass/conversions.html 我认为通用算法可以帮助您理解问题的基本思路,请尝试以下方法:http://www.cs.trincoll.edu/~ram/cpsc110/inclass/conversions.html

Thumbs up for tinkering with the sexagesimal system, it has great "mathematical beauty" and I haven't seen no one in ages doing something with it. 竖起大拇指来修补六分法系统,它具有出色的“数学美”,而且我很久以来都没有人看到有人对此做过任何事情。

You can't just do integer division of 455/60 and expect to get hours and minutes directly. 您不能只做455/60整数除法并期望直接得到小时和分钟。 It will be in hours and fraction. 将以小时为单位。

Instead you can: 相反,您可以:

diff_in_hours = (t1 - t2) / 60;
diff_in_mins = (t1 - t2) % 60;
printf("difference in time is %d : %d", diff_in_hours, diff_in_mins);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM