Welcome to the Parallax Discussion Forums, sign-up to participate.

TC
Posts: **1,019**

Hello all,

I am trying to find an elegant and simple way to scale a 8-bit value, to a 12-bit value. I made up a simple spreadsheet to help me figure out what would work, but I cant figure out what will work. On my spreadsheet I converted the 8-bit value, to a percentage, then took that percentage and scaled it up to a 12-bit value.

Would someone have a simple way to take a 8-bit value, and up scale it to a 12-bit value?

I did figure out that I need to shift the bits to the left 4 places, but that is as far as I have been able to figure out.

Thanks TC

I am trying to find an elegant and simple way to scale a 8-bit value, to a 12-bit value. I made up a simple spreadsheet to help me figure out what would work, but I cant figure out what will work. On my spreadsheet I converted the 8-bit value, to a percentage, then took that percentage and scaled it up to a 12-bit value.

X = ("8-bit value"/255)*100 "12-bit value" = (X / 100)*4095

Would someone have a simple way to take a 8-bit value, and up scale it to a 12-bit value?

I did figure out that I need to shift the bits to the left 4 places, but that is as far as I have been able to figure out.

Thanks TC

"CONFIDENCE"

The Feeling you get before you truely understand the situation.

The Feeling you get before you truely understand the situation.

## Comments

9 Commentssorted by Date Added Votes4,5880Vote UpVote Downie: Top most bits are repeated at the bottom. If you wanted, say, 8 bits to 24 bits, it's X = (value << 16) OR (value << 8 ) OR value

1,0190Vote UpVote DownThe Feeling you get before you truely understand the situation.

1,6400Vote UpVote DownX := value * 16

(spin)

X = value * 16 ;

(C)

Of course if you want FF to map to FFF, you'll need something like

X = value * 0xfff / 0xff ;

X := value * $FFF / $FF

depending on language.

6,8220Vote UpVote Down@evanh - the "AND 15" is redundant since it is an 8-bit value and there are no extra bits to mask off.

@Mark_T - shifting bits is always way more efficient as the Prop natively supports that whereas multiplication is much slower. Besides, I think bit shift is clearer for bit ops.

Tachyon Forth- compact, fast, forthwright and interactiveTachyon Forth News BlogTACHYON DEMONSTRATOR

Brisbane, Australia4,5880Vote UpVote DownYep, that's always a nice bonus if it's an option. Simply sum 'em all together and, voilà, extra depth for the cost of blurring.

6,1750Vote UpVote Down1,6400Vote UpVote Downconstants of low bit-count is usually good enough as there is considerable scope for adjusting filter coefficients

unless the stage has exceptionally high Q or high pass-band flatness is needed. FIR is much more expensive to calculate

as coefficients have to be more precise and there are many more of them (but fewer issues of stability).

I forget who, someone has posted a clever tool for Prop FIR code generation that commons up intermediate results

of the multiplies between coefficients in an FIR filter, which trades space for speed.

21,5830Vote UpVote Down-Phil

Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away.-Antoine de Saint-Exupery4,5880Vote UpVote DownTracy and Mark: The objective here is to gain extra bit depth. Don't do any dividing or shifting.

Sum of 16 consecutive samples gives 4 bits extra depth, job done.