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

位运算检测权限 #8

Open
loo41 opened this issue Nov 9, 2021 · 0 comments
Open

位运算检测权限 #8

loo41 opened this issue Nov 9, 2021 · 0 comments

Comments

@loo41
Copy link
Owner

loo41 commented Nov 9, 2021

js 存放数字是依照 IEEE 754 标准、

IEEE 754 = 1(符号位) + 11(指数位) + 52(小数位)

52 包含一位隐藏位 1,实际位 53 位

javascript 的位运算

  • << 左移运算符
    • 2 << 2 : 表示 .....010 转为 ....01000 = 8
  • & 按位或运算
    • 2 & 1 : 表示 .....010 & .....001 为 .....000 = 0
  • | 按位与运算
    • 2 | 1: 表示 .....010 & .....001 为 .....011 = 3

位运算计算权限

  • 定义权限
    • 可读 1
    • 可写 1 << 1
    • 可执行 1 << 2
    • 可编辑 1 << 3

计算用户是否具备某一个权限做或操作完之后等于权限值

​ 比如: 判断是否可写

​ 7 & 3(...0011) = ....0111 & ....0011 = ....0011 = 3

​ 1 & 3(...0011) = ....0001 & ....0011 = ....0001 = 1

​ 15 & 3(...0011) = ....1111 & ....0011 = ....0011 = 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant