• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Snippet] RightShift

JASS:
/************************************************
*
*   RightShift
*   v1.1.1.0
*   By Magtheridon96
*
*   - Used to perform the bitwise RIGHTSHIFT
*     operation for 8 bits. (1 byte)
*
*   API:
*   ----
*
*       function B_RIGHTSHIFT takes integer byte, integer n returns integer
*           - Returns (byte >> n)
*           - The arguments must be in the range [0x00 ... 0xff]
*           - The return value will be in the range [0x00 ... 0xff]
*
*       function B_RIGHTSHIFT_CARRY takes integer byte, integer n returns integer
*           - Returns the bits lost in (x) after (x >> n) is performed.
*           - B_RIGHTSHIFT_CARRY(0x5, 2) = 0x1
*           - B_RIGHTSHIFT_CARRY(0x5, 3) = 0x5
*
************************************************/
library RightShift
    
    function B_RIGHTSHIFT_CARRY takes integer byte, integer n returns integer
        return byte - byte / GetPowerOfTwo(n) * GetPowerOfTwo(n)
    endfunction
    
    function B_RIGHTSHIFT takes integer byte, integer n returns integer
        return byte / GetPowerOfTwo(n)
    endfunction
    
endlibrary

Yes, just another Bitwise operation snippet.
Nothing much to say really.

Feel free to comment, I guess..
 
Last edited:
JASS:
function B_RIGHTSHIFT takes integer byte, integer n returns nothing
    return byte / powersOfTwo[n]
endfunction

Like that?

The carry would have to be handled by the user, meaning while writing the MD5 library, I'd have to find the carries myself.

This way, this resource does exactly what people would expect it to do:
Rightshift a byte and that's it.

edit
First, I'm going to make a repository for powersOfTwo.
Having that code repeated in many libraries is a terrible idea.
 
Top