Results 1 to 7 of 7

Thread: C++ to VB code help, bit shifting

  1. #1

    Thread Starter
    Fanatic Member Geespot's Avatar
    Join Date
    Oct 2001
    Location
    Birmingham, UK
    Posts
    577

    C++ to VB code help, bit shifting

    Hi

    Im converting some c++ code to vb ( basically i dont know c++ well enough to do it in c++ )

    and ive come to this line

    x = (x<<13) ^ x;

    where x is a 32bit integer ( long in vb )

    Does anybody know how to convert this into a vb statement?

    Thanks.

  2. #2
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Code:
    Dim x As Long
    x = (x * 26) Xor x
    Should be correct.

    Z.

  3. #3
    Fanatic Member twanvl's Avatar
    Join Date
    Dec 2001
    Posts
    771
    A bit shift should be translated as *2^n, but that is really slow. If the shift is fixed you can calculate it first:
    VB Code:
    1. x = (x * 8192) Xor x 'x = (x<<13) ^ x;

  4. #4
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by twanvl
    A bit shift should be translated as *2^n, but that is really slow. If the shift is fixed you can calculate it first:
    VB Code:
    1. x = (x * 8192) Xor x 'x = (x<<13) ^ x;
    Duh, what was I thinking? -.-;;

    Z.

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Still far slower than a shift, but that cannot be helped. VB simply doesn't know shifts.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Junior Member
    Join Date
    Oct 2002
    Location
    MI
    Posts
    23
    Makes me glad that almost every C/C++ compiler out there automatically interprets that kinda stuff as a shift - even if you code it as multiplication.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    makes me sick. They didn't include shifts in VB because they thought programmers shouldn't be concerned with lowlevel issues, and I agree with them, we'd all be stuck with machine code otherways. A programming language should be abstract and independent of the machine.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width