Question Varbit bitmasks & shifts for significant value?

Discussion in 'Developer Support' started by Serene, Aug 2, 2016.

  1. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    917
    Likes Received:
    194
    Since Varbits are a 1 to 1 mapping to a specific value of a Varp that requires bitmasks on shifted bits, is there a way to get the bitmask & amount of shifts in a varp for specific varbits?

    This is kinda backwards since we already have the varbits class, but it would be useful for understanding how multiple values are contained in varps & the route it takes to focus on the specific bits for value extraction.

    Edit: Just realized we have a VarbitListener in the toolkit now. It kinda helps in mapping values to varbits & varbits to varps for real time value changing when logged in (as opposed to stopping & finding what varbit) but could this be used to help w/ finding the shifts/mask?
     
    #1 Serene, Aug 2, 2016
    Last edited: Aug 3, 2016
  2. SlashnHax

    SlashnHax The Chosen One

    Joined:
    Dec 10, 2014
    Messages:
    2,895
    Likes Received:
    824
    Basically there's a least significant bit and a most significant bit, the amount of shifts is the same as the least significant bit, e.g. lsb is 5 (6th from right), so we shift 5 times, then we apply a bitmask of length msb - lsb, basically CommonMath.getBitRange(value, lsb, msb).

    Lets say we had a Varp, and that the Varp had 16 bits. The first 8 bits from the left are for ThingA, and the last 8 are for ThingB. To get the 8 bits, we need to shift and mask. For A it's easy, shift 0, mask 8 (0b11111111), for B it's also easy, shift 8, mask 8. Varbits are good in that you don't need to worry about shifting and masking most of the time.
     
    Serene likes this.
  3. Serene

    Serene ( ͡° ͜ʖ ͡°)

    Joined:
    Mar 30, 2015
    Messages:
    917
    Likes Received:
    194
    Could you give me an example of how I could use this from the integer value returned from a Varp that carries two values?

    For example, Varp 1058 carries NMZ coffer amount and dream value. Endurance dream + 2k coins gives value of 32892. Dream varbit returns 124 and the coffer returns 2.

    Am I looking to convert that value of 32892 into a 16 bit-unsigned value, split that value into upper and lower and then shift/mask the upper & lower portions as you said to get the Varbit values of 124 and 2?
     
  4. SlashnHax

    SlashnHax The Chosen One

    Joined:
    Dec 10, 2014
    Messages:
    2,895
    Likes Received:
    824
    Look at it in binary, it's a lot easier to spot patterns and stuff like that
     

Share This Page

Loading...