Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting 8 bits to a scaled 12 bits equivalent

I need to convert an 8 bit number (0 - 255 or #0 - #FF) to its 12 bit equivalent (0 - 4095 or #0 - #FFF)

I am not wanting to do just a straight conversion of the same number. I am wanting to represent the same scale, but in 12 bits.

For example:-

0xFF in 8 bits should convert to 0xFFF in 12 bits

0x0 in 8 bits should convert to 0x0 in 12 bits

0x7F in 8 bits should convert to 0x7FF in 12 bits

0x24 in 8 bit should convert to 0x249 in 12 bits

Are there any specific algorithms or techniques that I should be using?

I am coding in C

like image 668
Remixed123 Avatar asked Oct 20 '25 09:10

Remixed123


1 Answers

Try x << 4 | x >> 4.

This has been updated by the OP, changed from x << 4 + x >> 4

like image 71
Paul Hankin Avatar answered Oct 22 '25 00:10

Paul Hankin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!