0% found this document useful (0 votes)
78 views3 pages

Question 2

Uploaded by

DARSHAN DARSH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

Question 2

Uploaded by

DARSHAN DARSH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

The binary numbers are the numbers which contain only Os and 1s.

And, the digital clocks use the binary numbers for telling the times.

In this program, the input would be the binary representation of time


and you need to convert that to the decimal notation in the 24-hour
format, similar to the digital clocks

Consider the input 0001 0010 0011 0101. There are 4 sequences of
the input and each sequence has 4 binary numerals. Each sequence
of the input is separated by a whitespace. The first 2 sequences
represent the hour and the remaining 2 sequences represent the
minutes. The first sequence of the input is 0001 which is decimal
number 1 and second sequence is 0010 translating as decimal
number 2. Thus the first 2 sequences represent the Hours of the
time which is 12. In the similar fashion, the last sequences can be
decoded as decimal number 35. Therefore, the input refers to the
time 12:35.

Note: The input represents a 24-hours time format and not the 12-
hour time format.

Function Description

Complete the function binaryTime To Decimal in the editor below.


The function must print the time after converting it as per the logic
above..

binary Time To Decimal has the following parameters:

binaryTime: The binary number representing the time.

Constraints

The input should always be a sequence of binary numbers.

The input should not breach the clock constraints, That is, it should
be not be negative and cannot accept input greater than 24 hours.
▼Input Format For Custom Testing

A sequence of binary integers which represent the time.

▼Sample Case 0

Sample Input For Custom Testing

Sample Output

12:35

Explanation

The first 2 sequences represent the hours of the time and translate to decimal number 12. The last 2
sequences represent the minutes and translate to decimal number 35. Thus the input represents the
time 12:35 on the clock.

▼Sample Case 1

Sample Input For Custom Testing

A
Sample Output

Invalid input

▼ Sample Case 1

Sample Input For Custom Testing

Sample Output

Invalid input

Explanation

Carefully notice that the first sequence is 00.11 which represents decimal number 3 and the last
sequence represent decimal number 13. Both these numbers are out of bounds for a valid time on
the clock. Thus, the above error.

You might also like