Searching \ for '[OT] Shifting individual bits to different positio' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/index.htm?key=shifting+individual
Search entire site for: 'Shifting individual bits to different positio'.

Exact match. Not showing close matches.
PICList Thread
'[OT] Shifting individual bits to different positio'
2005\09\13@233245 by Vitaliy

flavicon
face
>> I've heard about interesting trick shifting bits individually
>> into different positions by multiplying on constant on micros
>> with hardware multiplication unit.
>
> Pretty simple, actually.  A left shift (towards the MSB) is the
> same as a multiply by 2.  Each subsequent by 2 is a shift.

This is obvious, but I think Dmitriy had something else in mind: "shifting
bits individually into different positions." The keyword is "individually",
I don't see a reason to use hardware multiply if you can use shift
left/shift right.

Best regards,

Vitaliy

2005\09\14@075622 by Dave Tweed

face
flavicon
face
"Vitaliy" <spam_OUTspamTakeThisOuTspammaksimov.org> wrote:
> > > I've heard about interesting trick shifting bits individually
> > > into different positions by multiplying on constant on micros
> > > with hardware multiplication unit.
> >
> > Pretty simple, actually.  A left shift (towards the MSB) is the
> > same as a multiply by 2.  Each subsequent by 2 is a shift.
>
> This is obvious, but I think Dmitriy had something else in mind:
> "shifting bits individually into different positions." The keyword is
> "individually", I don't see a reason to use hardware multiply if you can
> use shift left/shift right.

Shift left/shift right on most microcontrollers only shift by one bit at
a time. Most DSPs have a unit called a "barrel shifter" (a huge array of
multiplexers) that can shift by any number of bits in constant time. The
"trick" is that a hardware multiplier can be used as a barrel shifter by
using the correct factors. If you have a multiply-accumulate instruction,
you can insert a bit (or a bit field) into a word in one instruction cycle.

You can even spread a bit or bitfield value over multiple positions if
you get clever. This is something that a plain barrel shifter can't do.
For example, suppose you have an 8-bit value that represents a grayscale
pixel. You can convert this to the equivalent RGB value packed into a
32-bit word by multiplying it by 0x00010101. If you want it left-justified
in the word, just change the constant to 0x01010100.

-- Dave Tweed

2005\09\14@124723 by Dmitriy Kiryashov

picon face
Hi Dave.

Any book ? webpage ? explaining roots of that ?


WBR Dmitry.


> For example, suppose you have an 8-bit value that represents a grayscale
> pixel. You can convert this to the equivalent RGB value packed into a
> 32-bit word by multiplying it by 0x00010101. If you want it left-justified
> in the word, just change the constant to 0x01010100.
> -- Dave Tweed

More... (looser matching)
- Last day of these posts
- In 2005 , 2006 only
- Today
- New search...