Results 1 to 5 of 5

Thread: [RESOLVED] Bit Shifting with C

Threaded View

  1. #1

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

    Resolved [RESOLVED] Bit Shifting with C

    I've come to understand C coding quite a bit over the past week. I am not a C programmer at all. Trying to convert/interpret some C code, I've come across the following simple calculations and am unsure what the results would be. I do not own a C compiler.

    If anyone could provide the answers to the these 2 calculations and/or answer my following question, I would very much appreciate it.

    All variables are defined as: int

    Calc 1: x4 =-17728437 x5 =-3330316
    x2 = (181 * (x4 + x5) + 128) >> 8

    Calc 2: x4 = 33479030 x5 = 6609623
    x2 = (181 * (x4 + x5) + 128) >> 8

    Where I'm having problems with this is that calcs above, before shifting, will result in a value that needs more than 32 bits.
    Is there some sort of variable type promotion?
    or possibly truncation?

    When this is the case, what part of the result, exactly, whether positive or negative, is shifted? just 32 bits, 32+ bits, something else?
    Last edited by LaVolpe; Dec 20th, 2011 at 01:43 PM.
    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}

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