Results 1 to 9 of 9

Thread: [RESOLVED] Zero fill right shift in VB6

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    16

    Resolved [RESOLVED] Zero fill right shift in VB6

    Hi,
    in Javascript we can convert a big number to 32 bit integer with Bitwise Operators, like this:
    Code:
    4066098149795 >>> 0; // result is: 3059087779
    How i can do this in VB6?

  2. #2
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    9,936

    Re: Zero fill right shift in VB6

    You're probably looking for this page or this page, or maybe even this page.

    Or, to just explore what Donald as assembled, you can start here.

    Enjoy,
    Elroy
    Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.

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

    Re: Zero fill right shift in VB6

    This can be done a different way also, but is limited to positive whole numbers in the Double range.

    First we need to get the value within the range 0 to 2^32. This part is a workaround of not being able to use MOD or integer division with doubles above the 2^31-1 range.
    Code:
    Dim d32 As Double, dNr As Double, shiftedValue As Long
    dNr= 4066098149795
    d32 = Int(dNr / 4294967296#)
    d32 = dNr - (d32 * 4294967296#)
    Now we can use long-standing unsigned to signed (Long) conversion
    Code:
        If d32 <= 2147483647# Then  ' compare to max positive long value: 2^31-1
            shiftedValue = d32 
        Else
            shiftedValue= d32 - 4294967296# ' result will be a negative Long or 0
        End If
    Note that shiftedValue can be a negative number due to the high bit being set.
    The value 3059087779 as a long is -1235879517, regardless the hex value is: B655F9A3

    Welcome to the forums
    Last edited by LaVolpe; Jul 19th, 2017 at 10:44 AM. Reason: added comments and the welcome
    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}

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Zero fill right shift in VB6

    DLL for Unsigned Long & Integer Arithmetic (see the second post for the version with shift and rotate operations) might do what you need.

    Supports both Integer and Long.

    However if this is about "big number" operations you may want another library that handles those.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2017
    Posts
    16

    Re: Zero fill right shift in VB6

    Quote Originally Posted by LaVolpe View Post
    This can be done a different way also, but is limited to positive whole numbers in the Double range.

    First we need to get the value within the range 0 to 2^32. This part is a workaround of not being able to use MOD with doubles above the 2^31-1 range.
    Code:
    Dim d32 As Double, dNr As Double, shiftedValue As Long
    dNr= 4066098149795
    d32 = Int(dNr / 4294967296#)
    d32 = dNr - (d32 * 4294967296#)
    Now we can use long-standing unsigned to signed (Long) conversion
    Code:
        If d32 <= 2147483647# Then  ' compare to max positive long value: 2^31-1
            shiftedValue = d32 
        Else
            shiftedValue= d32 - 4294967296# ' result will be a negative Long or 0
        End If
    Note that shiftedValue can be a negative number due to the high bit being set.
    The value 3059087779 as a long is -1235879517, regardless the hex value is: B655F9A3

    Welcome to the forums
    Thanks LaVolpe, your advice was always very useful.

  6. #6
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Zero fill right shift in VB6

    Quote Originally Posted by dilettante View Post
    DLL for Unsigned Long & Integer Arithmetic (see the second post for the version with shift and rotate operations) might do what you need.

    Supports both Integer and Long.

    However if this is about "big number" operations you may want another library that handles those.
    Yikes a compiled binary! Run for the hills!

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Zero fill right shift in VB6

    They are allowed in UtilityBank submissions.

  8. #8
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,451

    Re: Zero fill right shift in VB6

    Ah, good to know Kind of weird tough based on the admin feedback that binaries are just too dangerous to host....I guess everywhere but there for some reason. I'm sure it's a good reason too

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: Zero fill right shift in VB6

    Some things are impractical to post without the ability. One obvious case is an ActiveX DLL or OCX, where you really need to post a precompiled interface compatibility library (at least one with all members stubbed out) along with the source.

    Of course you can't just post binaries there, matching source is required and submissions are scrutinized more to ensure compliance.

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