I’m sorry but, why hex ?
If all you want is to pad the numbers with 0
s, hex has nothing do to with it.
I’ve never used BCD (why does this even still exist ?) with ignition so I have no idea how the values are interpreted, if it’s built-in or if you need to interpret them yourself, but I’d probably try to convert your Min_Sec
and Day_Hour
into a datetime object, then use this with whatever date formatting you may need.
Using expressions, you’d be looking at getDate()
and setTime()
, maybe something like
setTime(getDate(0, 0, {Day_Hour} >> 8), {Day_Hour} & 0xff, {Min_Sec} >> 8, {Min_Sec} & 0xff)
If you don’t want to create a datetime object because you only ever need to display dd hh:mm:ss
, then take @lrose’s expression. But I still don’t see the point of using hex conversion.
edit:
Wait, no, this is wrong. I forgot it was BCD, simply shifting 8 to the right won’t do the trick, as the 2 ‘nibbles’ (a nibble being half a byte) will be interpreted as an 8 bit integer.
Let me think about it and come back with a better solution.
re edit: Can you try lrose’s expression with numbers higher than 9 ? I’m expecting 07 to work fine because the 0 nibble is still 0, and 7 is still 7. But 11 (0001 0001) would be interpreted as 17, 12 as 18, etc…
re re edit: converting 4 BCD numbers encode into 16 bits to two 8 bits integers would look something like
left_byte = bcd >> 8
first_number = (left_byte >> 4) * 10 + (left_byte & 0x0F)
right_byte = bcd & 0xFF
second_number = (right_byte >> 4) * 10 + (right_byte & 0x0F)
Doing it with an expression would look quite ugly I think, so I’d make a function for this.
Then I still believe that using those to create a datetime object is not a bad idea.