Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Bit shifting in VB

Bit shifting in VB

Scheduled Pinned Locked Moved Visual Basic
8 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cnurse
    wrote on last edited by
    #1

    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

    D I 2 Replies Last reply
    0
    • C cnurse

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The bit shift operators are new to 2003. They don't exist in 2002... Sorry! RageInTheMachine9532

      C 1 Reply Last reply
      0
      • D Dave Kreskowiak

        The bit shift operators are new to 2003. They don't exist in 2002... Sorry! RageInTheMachine9532

        C Offline
        C Offline
        cnurse
        wrote on last edited by
        #3

        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

        D 1 Reply Last reply
        0
        • C cnurse

          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

          I Offline
          I Offline
          Ian Darling
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • I Ian Darling

            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

            C Offline
            C Offline
            cnurse
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • C cnurse

              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

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              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

              C 1 Reply Last reply
              0
              • D Dave Kreskowiak

                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

                C Offline
                C Offline
                cnurse
                wrote on last edited by
                #7

                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

                D 1 Reply Last reply
                0
                • C cnurse

                  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

                  D Offline
                  D Offline
                  Dave Kreskowiak
                  wrote on last edited by
                  #8

                  Yep, you can debug design-time code just about the same way you could under VB6. Microsoft was kind enough to supply a sample of it here[^]. RageInTheMachine9532

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups