|
-
Nov 29th, 2002, 07:54 AM
#1
Thread Starter
Fanatic Member
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.
-
Nov 29th, 2002, 10:00 AM
#2
Frenzied Member
Code:
Dim x As Long
x = (x * 26) Xor x
Should be correct.
Z.
-
Nov 29th, 2002, 10:09 AM
#3
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:
x = (x * 8192) Xor x 'x = (x<<13) ^ x;
-
Nov 29th, 2002, 02:10 PM
#4
Frenzied Member
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:
x = (x * 8192) Xor x 'x = (x<<13) ^ x;
Duh, what was I thinking? -.-;;
Z.
-
Dec 1st, 2002, 05:38 PM
#5
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.
-
Dec 4th, 2002, 04:02 PM
#6
Junior Member
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.
-
Dec 4th, 2002, 07:34 PM
#7
transcendental analytic
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|