Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Incrementing time represented as NBCD format
#2
FreeBasic code (tested with Win32 CVS Dec 5, 2006)

Code:
#Define HexPad( Number, Padding )   ( Right( String( Padding, "0" ) & Hex( Number ), Padding ) )

Type sTime Field = 1
  
   As uByte   Seconds, Minutes
  
End Type

Sub Inc( Byval pByte As uByte Ptr )
  
   *pByte += 1
   If ( ( *pByte And &H0F ) = &H0A ) Then *pByte += ( &H10 - &H0A )
  
End Sub


Sub IncTime( Byval pTime As sTime Ptr )
  
   Inc( @pTime->Seconds )
   If ( pTime->Seconds = &H60 ) Then
      pTime->Seconds = &H00
      Inc( @pTime->Minutes )
      If ( pTime->Minutes = &H60 ) Then pTime->Minutes = &H00
   End If
  
End Sub

Sub DisplayTime( Byval pTime As sTime Ptr )
  
   Dim As uByte   Seconds = ( ( pTime->Seconds Shr 4 ) * 10 ) + ( pTime->Seconds And &H0F )
   Dim As uByte   Minutes = ( ( pTime->Minutes Shr 4 ) * 10 ) + ( pTime->Minutes And &H0F )
  
   Print Using "##:##   0x"; Minutes; Seconds;
   Print HexPad( *cPtr( uShort Ptr, pTime ), 4 )
  
End Sub


Dim As sTime   Clock


DisplayTime( @Clock )
For X As Integer = 1 to 60 * 60
  
   IncTime( @Clock )
   DisplayTime( @Clock )
  
Next

Sleep
End
Life is like a box of chocolates', hrm, WTF, no it isn't, more like, 'life is like a steaming pile of horse crap.'
Reply


Messages In This Thread
Incrementing time represented as NBCD format - by 1000101 - 12-06-2006, 12:28 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)