>>= bitwise operations >> 
Author Message
 >>= bitwise operations >>

Hiya,


graphics problems but unfortunately they are mainly {*filter*} c programmers.
So my questions is, is there a Visual Basic equivalent operation for
shifting bits such as

red = (highcolor16 & 0xf800)>>11; // top 5 bits
green = (highcolor16 & 0x7e0)>>5; // middle 6
blue = highcolor16 & 0x1f;  // bottom 5

red = (highcolor15 & 0x7c00)>>10; // top 5 bits
green = (highcolor15 & 0x3e0)>>5; // middle 5
blue = highcolor15 & 0x1f;  // bottom 5

red <<= 3;
green <<= 2;   // green <<=3; if 15bit
blue <<= 3;

(obviously the comments, hex notation and line ends are different too).

Any help would be greatly appreciated. Surely vb is not so limited that it
can't do something as elementary as this.

Brian.



Fri, 01 Dec 2000 03:00:00 GMT  
 >>= bitwise operations >>

Easy. Each shift is simply an integer divide by 2. Raise 2 to the shift
value before dividing.

So:

Quote:
>red = (highcolor16 & 0xf800)>>11; // top 5 bits

becomes:

red = (highcolor16 And &hf800) \ 2^11

and:

Quote:
>green = (highcolor16 & 0x7e0)>>5; // middle 6

becomes:

green= (highcolor16 And &h7e0) \ 2^5

and so on ...

Of course this will be MUCH slower than C's shifts, which are true bitwise
shifts and can be done with a single machine instruction in optimized code.

Good luck!

Steve



Fri, 01 Dec 2000 03:00:00 GMT  
 >>= bitwise operations >>


Quote:

>Easy. Each shift is simply an integer divide by 2. Raise 2 to the shift
>value before dividing.

>So:

>>red = (highcolor16 & 0xf800)>>11; // top 5 bits

>becomes:

>red = (highcolor16 And &hf800) \ 2^11

If highcolor16 is an Integer, you will get "sign extension" problems if
the highcolor16 contains the &h8000 bit.
    Correct with:

        red = red And &h1f

    Don't eliminate the first mask because right shifting is not the same
as divide by two when there is a nonzero remainder and the dividend is
NEGATIVE.  For example, (-1)/2 = 0 { note, remainder is nonzero } while
(unsigned)(-1)>>1 = 32767 { in 16-bit mode } and (signed)(-1)>>1 = -1 { in
16- or 32-bit mode }.

Henry S. Takeuchi

Seattle, Washington (USA)



Fri, 01 Dec 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. <<<<<<<<ComboBox>>>>>>>>>>>>

2. using The Shell Command >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

3. >>>>>>While Not rst.EOF

4. PSUDOCODE HELP >>>>>>>>>>>

5. >>>>> Serial Communications

6. VB5 >>>>> Academic Version

7. <<<<HELP- OLE container Control>>>>>>>>>

8. CopyMemory (RtlMoveMemory) >>> Illegal operation

9. !!! URGENT HELP REQUIRED !!!>>>>>>>>

10. Please Help --------->>>>AppLink Problem

11. VB3 ->->->->VBDOS??

12. >>>> HELP WITH RUNTIME FILES

 

 
Powered by phpBB® Forum Software