...
/Solution: Convert 2-Bytes Time Into Hours, Minutes, and Seconds
Solution: Convert 2-Bytes Time Into Hours, Minutes, and Seconds
Follow the step-by-step instructions to convert 2-bytes time into hours, minutes, and seconds.
We'll cover the following...
Solution
RUN the code given below and see its output!
Press + to interact
# include <stdio.h>void displayTime ( unsigned short int time ) ;int main( ){unsigned short int time ;time = 10000 ;displayTime ( time ) ;return 0 ;}void displayTime ( unsigned short int tm ){// Declare variablesunsigned short int hours, minutes, seconds, temp ;// Extract hourshours = tm >> 11 ;// Extract minutestemp = tm << 5 ;minutes = temp >> 10 ;// Extract secondstemp = tm << 11 ;seconds = ( temp >> 11 ) * 2 ;// Display hours minutes and secondsprintf ( "For Time = %hu\n", tm ) ;printf ( "Hours = %hu\n", hours ) ;printf ( "Minutes = %hu\n", minutes ) ;printf ( "Seconds = %hu\n", seconds ) ;}
Explanation
The program given above converts 10000 into 4:56:32. To carry out the conversion, the <<
and >>
operators are suitably used as shown in the code. In this 2-byte number ...
Access this course and 1400+ top-rated courses and projects.