Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bit shifting in skript #140

Open
uiytt opened this issue Aug 24, 2019 · 6 comments
Open

Bit shifting in skript #140

uiytt opened this issue Aug 24, 2019 · 6 comments
Labels
priority: low Not essential, but would be nice to complete (quality-of-life) status: more info needed A better explanation/justification of a bug report/feature request is needed type: enhancement

Comments

@uiytt
Copy link

uiytt commented Aug 24, 2019

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

@btk5h
Copy link
Owner

btk5h commented Aug 24, 2019

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 btk5h added priority: low Not essential, but would be nice to complete (quality-of-life) status: more info needed A better explanation/justification of a bug report/feature request is needed type: enhancement labels Aug 24, 2019
@uiytt
Copy link
Author

uiytt commented Aug 24, 2019

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.... :/)

@btk5h
Copy link
Owner

btk5h commented Aug 25, 2019

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

@uiytt
Copy link
Author

uiytt commented Aug 25, 2019

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 ?

@btk5h
Copy link
Owner

btk5h commented Aug 25, 2019

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.

@uiytt
Copy link
Author

uiytt commented Aug 25, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: low Not essential, but would be nice to complete (quality-of-life) status: more info needed A better explanation/justification of a bug report/feature request is needed type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants