Results 1 to 6 of 6

Thread: [RESOLVED] MsgBox(256 >> 2) In VB6

  1. #1

    Thread Starter
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Resolved [RESOLVED] MsgBox(256 >> 2) In VB6

    Hi,

    Im not sure how they call it, but I call it Binary rotation.
    In VB.NET I can easily rotate numbers using something like this:

    Code:
    MsgBox(256 >> 2)          '// Wich will return: "64".

    But on VB6 It won't work, so I need to know if there is a function in vb6 that maybe I don't know about, that can replace the ">>" or "<<" ?

    Please help, thanks.
    DoEvents

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: MsgBox(256 >> 2) In VB6

    There are no explicit left and right shift operators in VB6. You can use something like:

    256 \ 4

    Left and right rotate are entirely different things, and I don't think VB.Net even supports those.

  3. #3

    Thread Starter
    Addicted Member reacen's Avatar
    Join Date
    Jul 2009
    Location
    c:\windows\system32\gdi32.dll
    Posts
    243

    Re: MsgBox(256 >> 2) In VB6

    Umm.. I have a decryption algorithm in VB.NET that uses ">>" and "<<" everywhere, so I need to convert it in VB6.

    I was thinking of converting numbers to binary string "010101" then rotate left/right, then convert to Long, but its verry slow. I need to know if there is an other way?
    DoEvents

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: MsgBox(256 >> 2) In VB6

    With some forms of decryption, rotation is used. I have a project on planetsourcecode that has a rotation algo you might want to look at.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: MsgBox(256 >> 2) In VB6

    See ">> and << functions for VB" in my signature.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  6. #6
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: MsgBox(256 >> 2) In VB6

    In base 10, you can do *10, and often school children are taught the trick just add that many zeros. Thus 30*10 is 300, 20*100 is 2000, and so on. These are powers of 10. 10^1 and 10^2 respectively(and 10^3 is 1000).

    Binary(base 2) works the same way with powers of 2. 2*2=4 which in binary is B10 to B100, 2*4(B10*B100) = 8(B1000), 2*8(B10*B1000) = 16(B10000), and so on. The same works with division, only removing digits.

    To rotate, you can mask the bits with AND, and shift them(multiplication or division with powers of 2), then combine them back with OR.

    For example, lets take the number(assuming type byte) 170, in binary that's B10101010. Now lets figure out how to rotate it. To create a bit mask for the AND portion, we'll take our power of two and subtract one. Lets say we want to shift it 2 bits to the right, that's 2^2 or 4(B100), subtract 1, gives us 3(B11), that's the mask we need. So then take (3 And 170), which is 2(B10). Now we need to shift that to align to the left side of a byte. 2^8 is 256, which would shift an entire byte. We need two bits less than that. So: 2^(8-2) is 2^6(which is 64). So then, we get:

    vb Code:
    1. ShiftRight = 4 'should be 1 to 7, ideally
    2. lNumber = 171  'should be a byte 0-255
    3. lNumber = (lNumber \ 2 ^ ShiftRight) Or (((2 ^ ShiftRight - 1) And lNumber) * 2 ^ (8 - ShiftRight))
    4. '         'normal shift            ' +  'create mask         and apply it ' 'shift the masked bits'
    5. Debug.Print lNumber

    Again, this is only designed for Byte. Other types are going to be signed, and you'll have to deal with the sign bit.

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