Bit shifting in VB
-
Can I use bit shifting operators in VB. According to MSDN I can. But...my msdn library is 2003 and my VB is 2002! Do I have to import something because I see erros when I try a = B >> 2. I am using VB 2002. Thanks you lot! Nursey
The bit shift operators are new to 2003. They don't exist in 2002... Sorry! RageInTheMachine9532
-
The bit shift operators are new to 2003. They don't exist in 2002... Sorry! RageInTheMachine9532
Hey Rage, I thought as much, presumably they are in C# so really I could just knock up a quick C# object which offers bit shifting and byte extraction from 32-bit ints, the stuff we take for granted in C++. As a feeler, how long has it taken people to get to grips with C# if you know C++, or VB for example? Just another language is what I say, and they should all be learned if possible, it helps you to think outside the box. Chris. Nursey
-
Can I use bit shifting operators in VB. According to MSDN I can. But...my msdn library is 2003 and my VB is 2002! Do I have to import something because I see erros when I try a = B >> 2. I am using VB 2002. Thanks you lot! Nursey
The previous poster is correct - the shifting operators are 2003 only. However, if you have an integer value you can mimic some of the shifting by dividing or multiplying by two, although this is far from perfect and may cause overflow errors and suchlike. You might also find that you can bit mask, and created the shifted up or down value by adding or subtracting the relevant powers of 2 to an initial zero value. You could also create a lookup table of shifts if you don't mind the memory overhead, but this would be fast and simple (note this is only really practical for small bitfields, of size 8 bits or there abouts (an array 256 Bytes each way) - 32 bits woud be right out due to needing 4 gig of memory for each :-D) Or upgrade your project to 2003 :-) -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
-
The previous poster is correct - the shifting operators are 2003 only. However, if you have an integer value you can mimic some of the shifting by dividing or multiplying by two, although this is far from perfect and may cause overflow errors and suchlike. You might also find that you can bit mask, and created the shifted up or down value by adding or subtracting the relevant powers of 2 to an initial zero value. You could also create a lookup table of shifts if you don't mind the memory overhead, but this would be fast and simple (note this is only really practical for small bitfields, of size 8 bits or there abouts (an array 256 Bytes each way) - 32 bits woud be right out due to needing 4 gig of memory for each :-D) Or upgrade your project to 2003 :-) -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky
Having put your 4 Gig of memory method to the test I seem to have scratched the area of my hard disk, right around the place where the swap file seems to go ;-) I am gonna go the C# route just to have a little utility function until my 2003 hits the front door carpet. I was using the div mul method of shifting up until now though and who cares if its 4 nano seconds slower than the C++ like bit shifts! Ah well, all I have to do now is wait for the garbage collector to give me my 4 gig back hahaha 8-) See Yah! Nursey
-
Hey Rage, I thought as much, presumably they are in C# so really I could just knock up a quick C# object which offers bit shifting and byte extraction from 32-bit ints, the stuff we take for granted in C++. As a feeler, how long has it taken people to get to grips with C# if you know C++, or VB for example? Just another language is what I say, and they should all be learned if possible, it helps you to think outside the box. Chris. Nursey
And your right my friend! This is what learning all those different languages is all about! I prefer VB for the bulk of my code just because it's fast to write up. But I also write components in C# and C++, and for the real down and dirty with API's, NetWare, and libraries, in use C++. It didn't take very long at all to get used to C#, having a background in both VB and C++, it was a snap to learn. It just took a couple weeks to get used to the hybrid syntax!:-D In all, I think I have my hands in something like 14 different languages. I'm by no means a master of all of them, but the concepts are the same amongst them all. But you're right! The more you know, the better off you are! RageInTheMachine9532
-
And your right my friend! This is what learning all those different languages is all about! I prefer VB for the bulk of my code just because it's fast to write up. But I also write components in C# and C++, and for the real down and dirty with API's, NetWare, and libraries, in use C++. It didn't take very long at all to get used to C#, having a background in both VB and C++, it was a snap to learn. It just took a couple weeks to get used to the hybrid syntax!:-D In all, I think I have my hands in something like 14 different languages. I'm by no means a master of all of them, but the concepts are the same amongst them all. But you're right! The more you know, the better off you are! RageInTheMachine9532
Well, as soon as I have put some polish on this current control library I'll dive into C#. I have a feeling the hybrid syntax will be pretty intuitive. I just have to remember to keep putting the ";" in the right places again! Have you used any free tracing tools that help you to dig out strange bugs which are hard to track down at design time? I was getting "Null reference exception..." and I couldn't pinpoint the line which it was at until I put some message boxes in. It seems at design time code gets run which you can't step through. I remember running two copies of VB6 to debug controls at design time. Presumably that's still an option? Ta. Nursey
-
Well, as soon as I have put some polish on this current control library I'll dive into C#. I have a feeling the hybrid syntax will be pretty intuitive. I just have to remember to keep putting the ";" in the right places again! Have you used any free tracing tools that help you to dig out strange bugs which are hard to track down at design time? I was getting "Null reference exception..." and I couldn't pinpoint the line which it was at until I put some message boxes in. It seems at design time code gets run which you can't step through. I remember running two copies of VB6 to debug controls at design time. Presumably that's still an option? Ta. Nursey