Categories
Welcome Center
Education & Development
Cyber Security
Virtualization
General
Certification Preparation
Project Management
Posts
Groups
Training Resources
Infosec
IT & Security Bootcamps
Practice Exams
Security Awareness Training
About Us
Home
General
Off-Topic
Possible Math Problem
the_Grinch
Working on a program and I need to get timestamps. In order to get the timestamps I have to convert them from one string to a string of 0's and 1's. The length of the 0's and 1's is 1440 (number of minutes in a day). As a short example, 001001, the 1's correspond to the minute of the day it occurred thus these would be 00:03 and 00:06. Any thoughts on how I could take the place of the 1's (in the example 2 and 5) and convert that so it would appear as 00:03 and 00:06? I figure there should be some sort of math I could do so that when I get a 1 at place 937 I can easily convert it to the time.
Find more posts tagged with
Comments
NetworkNewb
Loop through string until it finds a 1. Find which spot in the string it is. Use that number and divide by 60. Use that result's whole number as the hours. Then use the "%" operator in Python to find the remaining minutes. 68 % 60 = 8. Stick a ":" in the middle of the two results.
Guessing there is someway to put a 0 in front the numbers if the result on either side of the ":" is less than 10 too.
the_Grinch
You are the man! Pretty sure this will work!
the_Grinch
for i, ltr in enumerate(working_value):
if ltr == '1':
hour = i // 60
min = i % 60
time = str("{0:0>2}".format(hour)) + ":" + str("{0:0>2}".format(min))
This was the code I wrote and it worked perfectly! Thanks again NetworkNewb!
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of