cm****@hotmail.com wrote:
Hi
C++ should provide us bit shift but fill with 1 rather than 0.
Why 'should'?
Or i am wrong, c++ have it???
Not everything you or I will ever need os provided by the language. But the
language is powerful enough that you can synthesize what you need from what
is existing.
result = ( value << 1 ) | 0x01;
does what you want. First shift one position to the left, then
set the leftmost bit to 1
For 'shift values' other then 1, I think the easieast approch is
to use a lookup table:
unsigned int MyShiftLeft( unsigned int What, unsigned int How )
{
static unsigned int OnePattern[] = { 0, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
return (What << How ) | OnePattern[How];
}
This works for values of 'How' up to 7. If that is not enough, enlarge the table.
--
Karl Heinz Buchegger
kb******@gascad.at