skript-mirror icon indicating copy to clipboard operation
skript-mirror copied to clipboard

Bit shifting in skript

Open uiytt opened this issue 6 years ago • 6 comments

Is your feature request related to a problem? Please describe. So its the second time since I start using skript-mirror (I started not long ago) that I need to use bit shifting for an algorithme (>> in java) Ex : 4>>2 = 1

Complete explanation here : https://stackoverflow.com/questions/141525/what-are-bitwise-shift-bit-shift-operators-and-how-do-they-work

Describe the solution you'd like an expression like %object%>>%number% that return the value of the object after the shifting...

Describe alternatives you've considered Some peoples says that: A>>3 is equal to divise something by 8 (2 * 2 * 2) A<<5 is equal to multiple something by 32 (2 * 2 * 2 * 2 * 2) But this is not the exact same things, bit shifting when shifting too far remove bit, see more here

uiytt avatar Aug 24 '19 04:08 uiytt

Do you have a use case for this? More often than not, bit shifts are used to manipulate bitmasks, which skript-mirror's bits expression already lets you do and in a much more readable way.

btk5h avatar Aug 24 '19 19:08 btk5h

Well I wanted to do something like that :

BufferedImage img = ....

public boolean isTransparent( int x, int y ) {
  int pixel = img.getRGB(x,y);
  if( (pixel>>24) == 0x00 ) {
      return true;
  }
}

Do you know how I can make something like that with the bit expression (I don't really understand the expression well.... :/)

uiytt avatar Aug 24 '19 22:08 uiytt

Please take a look at the docs for the bits expression.

btk5h avatar Aug 25 '19 01:08 btk5h

Already seen it but I'm lost 🤔 Normal bit shifting only need two argument, why is there 3 to 4 args ? (Yeah I'm not really good :( ) Is this something like this : add 3 to {_number}'s bits ? but what are the last two arguments for ?

uiytt avatar Aug 25 '19 05:08 uiytt

The bits expression is not a bit shift. The entire purpose of the expression is to prevent the user from even having to think about bit shifting.

Example: If you have a number in binary such as 0b0001001000 and you want to manipulate the bolded numbers, the bits expression will allow you to manipulate the value 0b10010 without thinking about its position in the original number.

btk5h avatar Aug 25 '19 06:08 btk5h

%numbers%'[s] (bit %number%|1¦bit(s| range) [from] %number%( to |[ ]-[ ])%number%) {_nombre}'s bit range from 1 to 1 -> give the first bit ?

uiytt avatar Aug 25 '19 17:08 uiytt