• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[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