Dismiss Notice
Want to Shorten Your Long URL? Check out our sister website Tiniurl to solve your needs!

Question Mathematics

Discussion in 'C/C++' started by thenewcomer, Jul 10, 2013.

  1. thenewcomer

    thenewcomer Registered User

    Likes Received:
    Jun 2, 2010
    This is probably being posted in the wrong section, but i figured one of you guys could help me out.

    I need to convert
    val = buf&0x7F;
    while (buf[i++]&0x80)
    val |= (buf&0x7F)<<(i*7);

    into a human readable math equation. think anyone can help me out? (dont worry about converting the hex, i can do that. just the i++ and << make my brain hurt everytime i try and think of an equation)

    p.s. if anyone is wondering, this is a u30 to int conversion. i figure if i can make an equation for it, i can reverse the equation and have an int to u30 equation which would save me much time.
    Last edited: Jul 10, 2013
  2. FlowerzNDaizyz

    FlowerzNDaizyz =>> The Supervisor <<=

    Likes Received:
    Feb 24, 2015
    Well, I found that on good ol Stack overflow:
    God I am horrible at math. I hate bitwise operators too.
    Considering I am young and haven't taken any "higher level" math classes I've never seen an equation where you would increment a value each time.

    Just try printing out val and then following up with the same sort of thing each time you go through the loop.
    It's much easier to go from equation to code, rather than the other way around.

    A bit wise and of 0 and 127 is going to result in zero.

    What this code does is:
    Assign val as 0 AND 127. (Which is in fact zero)
    For as long as the value of the buffer is less than 128, it will continue the execution of the while loop. This means it will loop 127 times.
    After this point I am befuddled xD
    If I was not so tired I could help you more.

    But why on Earth do you want to convert this into an equation?
    Last edited: Feb 25, 2015

Share This Page