B4R Question int value from byte

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private bc As ByteConverter
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   ReadDate("01.09.2016 16:49:45")
End Sub

Sub ReadDate(data() As Byte)
  Log("Date time>>",data)
   'step 1: get the correct substring
   'step 2: convert it to string as array of bytes cannot be directly converted to numbers
  Dim day As Int = bc.StringFromBytes(bc.SubString2(data, 0, 2))
  Dim month As Int = bc.StringFromBytes(bc.SubString2(data, 3, 5))
  Dim year As Int = bc.StringFromBytes(bc.SubString2(data, 6, 10))
   Log(day, "/", month, "/", year)
End Sub
 
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
B4X:
Sub Process_Globals
   Public Serial1 As Serial
   Private bc As ByteConverter
End Sub

Private Sub AppStart
   Serial1.Initialize(115200)
   Log("AppStart")
   ReadDate("01.09.2016 16:49:45")
End Sub

Sub ReadDate(data() As Byte)
  Log("Date time>>",data)
   'step 1: get the correct substring
   'step 2: convert it to string as array of bytes cannot be directly converted to numbers
  Dim day As Int = bc.StringFromBytes(bc.SubString2(data, 0, 2))
  Dim month As Int = bc.StringFromBytes(bc.SubString2(data, 3, 5))
  Dim year As Int = bc.StringFromBytes(bc.SubString2(data, 6, 10))
   Log(day, "/", month, "/", year)
End Sub
Thanks @Erel
 
Upvote 0
Top