B4R Question int value from byte

Erel

Administrator
Staff member
Licensed 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
 

Tayfur

Well-Known Member
Licensed 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
 
Top