# Converting numbers to a different format

Ok, so I have, what I feel like should be a simple task, but I can't seem to figure it out.

I am re-purposing an old device that is some sort of counter. Each time it counts up, it sends out the value in three serial bytes, but it sends it out in a strange format. Instead of counting up like you'd expect (0x00 00 00, 0x00 00 01, etc), it counts up like this (starting with the first value):

0x01 00 01
0x01 00 02
...
0x01 00 08
0x01 01 01
...
0x01 19 08
0x02 00 01
etc

The rightmost byte counts 0x01-0x08, the middle byte 0x00-0x19, and the leftmost byte 0x01 to 0x91. What I want to do is take these strange numbers and convert them to a form that would be what you'd expect from a counter. For instance, 0x01 00 01 would get converted to 0, 0x01 00 02 to 1, 0x01 01 01 to 8, etc. What would be the best way to do this? I've tried to think of mathematical operations that would work, but its just not coming. The value needs to be calculated individually for each number, because user input on the counter device can cause the number to skip ahead or skip back.

(And no, changing to a different counter device isn't an option! )

Am I correct that counting goes :0x01 01 01

0x01 00 01
0x01 00 02
0x01 00 03
0x01 00 04
0x01 00 05
0x01 00 06
0x01 00 07
0x01 00 08
0x01 01 01
0x01 01 02
0x01 01 03
0x01 01 04
0x01 01 05
0x01 01 06
0x01 01 07
0x01 01 08
0x01 02 01
0x01 02 02

so there is not

0x01 00 00
0x01 01 00

==================

A little more detials of what comes next.
like what happens after an hour ?

Gray code of some sort?

Not quite enough info to be sure but try

third byte + 9second + 269*first

This assumes the third byte is a base 9 counter, the second, base 26.

How many minutes in 1 day, 2 hours and 3 minutes? Remember minutes counts 0-59 in an hour.

((1 *24) + 2) *60 + 3

Yours is more like...
((B1 * 20) + B2) *8 + B3

line_code:
Ok, so I have, what I feel like should be a simple task, but I can't seem to figure it out.

I am re-purposing an old device that is some sort of counter. Each time it counts up, it sends out the value in three serial bytes, but it sends it out in a strange format. Instead of counting up like you'd expect (0x00 00 00, 0x00 00 01, etc), it counts up like this (starting with the first value):

0x01 00 01
0x01 00 02
...
0x01 00 08
0x01 01 01
...
0x01 19 08
0x02 00 01
etc

The rightmost byte counts 0x01-0x08, the middle byte 0x00-0x19, and the leftmost byte 0x01 to 0x91. What I want to do is take these strange numbers and convert them to a form that would be what you'd expect from a counter. For instance, 0x01 00 01 would get converted to 0, 0x01 00 02 to 1, 0x01 01 01 to 8, etc. What would be the best way to do this? I've tried to think of mathematical operations that would work, but its just not coming. The value needs to be calculated individually for each number, because user input on the counter device can cause the number to skip ahead or skip back.

(And no, changing to a different counter device isn't an option! )