Click to See Complete Forum and Search --> : C++ to VB code help, bit shifting
Geespot
Nov 29th, 2002, 06:54 AM
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.
Zaei
Nov 29th, 2002, 09:00 AM
Dim x As Long
x = (x * 26) Xor x
Should be correct.
Z.
twanvl
Nov 29th, 2002, 09:09 AM
A bit shift should be translated as *2^n, but that is really slow. If the shift is fixed you can calculate it first:
x = (x * 8192) Xor x 'x = (x<<13) ^ x;
Zaei
Nov 29th, 2002, 01:10 PM
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:
x = (x * 8192) Xor x 'x = (x<<13) ^ x;
Duh, what was I thinking? -.-;;
Z.
CornedBee
Dec 1st, 2002, 04:38 PM
Still far slower than a shift, but that cannot be helped. VB simply doesn't know shifts.
Zaffir
Dec 4th, 2002, 03:02 PM
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.
kedaman
Dec 4th, 2002, 06:34 PM
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.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.