+ Reply to Thread
Results 1 to 4 of 4
  1. Stayed at a Holiday Inn.. the_Grinch's Avatar
    Join Date
    May 2007
    Posts
    3,846

    Certifications
    BS-CST CISSP GMON MPSC Security+ XRY 1+2+3 XAMN AAA AA CMFF CCO CCPA
    #1

    Default Possible Math Problem

    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.
    WIP:
    MS in Legal Studies - Drexel University
    Mobile Forensics
    Kotlin
    Python
    Reply With Quote Quote  

  2. SS -->
  3. They are watching you NetworkNewb's Avatar
    Join Date
    Feb 2015
    Location
    Off the grid
    Posts
    2,663

    Certifications
    A+/Net+/Sec+, CCENT, CCNA:Sec, CCSK, GCIH
    #2
    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.
    Reply With Quote Quote  

  4. Stayed at a Holiday Inn.. the_Grinch's Avatar
    Join Date
    May 2007
    Posts
    3,846

    Certifications
    BS-CST CISSP GMON MPSC Security+ XRY 1+2+3 XAMN AAA AA CMFF CCO CCPA
    #3
    You are the man! Pretty sure this will work!
    WIP:
    MS in Legal Studies - Drexel University
    Mobile Forensics
    Kotlin
    Python
    Reply With Quote Quote  

  5. Stayed at a Holiday Inn.. the_Grinch's Avatar
    Join Date
    May 2007
    Posts
    3,846

    Certifications
    BS-CST CISSP GMON MPSC Security+ XRY 1+2+3 XAMN AAA AA CMFF CCO CCPA
    #4
    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!
    WIP:
    MS in Legal Studies - Drexel University
    Mobile Forensics
    Kotlin
    Python
    Reply With Quote Quote  

+ Reply to Thread

Social Networking & Bookmarks