Results 1 to 15 of 15

Thread: How to translate >> to VB

  1. #1

    Thread Starter
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478

    How to translate >> to VB

    I've seen a syntax line in C like

    *crcres = *crcres >> 1

    does someone know what this does and how to write it in VB

    Advanced thanks
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    It does a binary right-shift by one bit.

    As far as I know, VB can't do that...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    It's similar to this:

    crcres = crcres \ 2

    ..but I don't think that maps exactly to the function you specified

  4. #4
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Lokks like you're doing CRC32 - attached is a VB version plus dll
    Attached Files Attached Files

  5. #5
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710

    Re: How to translate >> to VB

    Originally posted by swatty
    *crcres = *crcres >> 1
    Shoulda been
    Code:
    (*crcres) >>= 1;
    =).

    Z.

  6. #6
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Yeah - like strlen is really something like:
    Code:
     for(buf=string, i=0;*buf;buf++) i++; return i;
    when it's not assembler.

    Our core C code is: -abstracted, inlined, jammed, proffed, and reduced to the max. But, that doesn't mean a new guy should ever try it.

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    /me completely fails to grok that last sentence...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    You know it jim, but regardless, it should be drilled into the brain of newcomers that using the <operator>= operators when appropriate is GOOD!

    =).

    Z.

  9. #9
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    Z.
    uh huh... But most people who post here couldn't really read the stuff. I routinely 'tone down' everything I post. The idea is to communicate, not obfuscate. 90% of what I do is in ANSI C.

    Parksie -
    don't you try to inline, jam, etc, your core code? ie., optimize the living doo-doo out of your code? Especially the core code - primitives? We clock() on everything because the stuff gets called hundreds of millions of times a day. Literally. 5% gets you five minutes.

    We have tables that have 100 million+ records. Full table scans net lots of traffic into the core modules. For example, Archive-purge runs over 10 hours. We want it to run in 5 or less.
    It cleans out datasets.

  10. #10
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    100 million... my mind boggles at that number =).

    I know what you mean. Things that seem really obvious to me now wont even occur to someone who has only been using c/c++ for a few months... and again, in a year or so, there will be things that are just natural where they wouldnt even have occured to me now.

    Z.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    If you have such heavily frequented code you might consider writing the tightest loops in assembler.

    To translate bitshifts to VB you can use division/multiplication, it's just that it is much slower.

    var <<= i;
    =
    var = var * 2^i

    var >>= i;
    =
    var = var / 2^i
    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.

  12. #12
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Use the integer divide, in this case, as it is faster:
    Code:
    var  = var \ 2^i
    Z.

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And prduces better results, as you don't want it to be converted to a floating point number (usually).
    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.

  14. #14
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Yupper.

    Z.

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by jim mcnamara
    Parksie -
    don't you try to inline, jam, etc, your core code? ie., optimize the living doo-doo out of your code? Especially the core code - primitives? We clock() on everything because the stuff gets called hundreds of millions of times a day. Literally. 5% gets you five minutes.
    Yeah, I do. We have to do about 100 calculations per finite element, of which some meshes have a few hundred thousand.

    I did some *really* horrible-looking parser code a few days ago, but it sped it up from 6 hours to about 40 seconds.

    There's nothing wrong with optimising. Just don't do it too early. Get it working first!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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