encoding data in bytes - how to split into nibbles

304 views Asked by At

I have a voltage reading 0-5v and I need a precision of 0.1.

Can I encode this in a 1 byte? How would I split the it into nibbles, the first nibble being the volt and the second nibble being the decimal?

Would be helpful if somebody could explain with an example?

Thanks C

1

There are 1 answers

0
tripleee On

If your input is 4.9 you can encode 4 as 0100 and 9 as 1001.

Depending on what you want to accomplish, it may make more sense to store this information directly as an integer that the computer can read and understand without any transformations (e.g. store 4.9 as 49, binary 0011 0001).