Java ( 1 << 2) 中的这个表达式是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9833050/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 08:20:36 来源:igfitidea点击:
What is this expression in Java ( 1 << 2)?
提问by thuclh
I don't know what this means "1 << 2" in :
我不知道这是什么意思“1 << 2”:
public static final int MODIFY_METADATA = 1 << 2; // modify object
Please help me!
请帮我!
回答by Jeffrey
回答by Peter Lawrey
If you want to know why would use use 1 << 2
rather than 4 which is the same value, it because you explicitly want to be using a bit mask e.g.
如果您想知道为什么要使用 use1 << 2
而不是 4 是相同的值,那是因为您明确希望使用位掩码,例如
public static final int FLAG0 = 1 << 0;
public static final int FLAG1 = 1 << 1;
public static final int MODIFY_METADATA = 1 << 2;
Shows each value is in a bit mask.
显示每个值都在位掩码中。