何时web开发过程中使用位运算符? [英] When to use Bitwise Operators during webdevelopment?

查看:175
本文介绍了何时web开发过程中使用位运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然我把握位运算符的概念,我不能说,我在过程中,我不得不求助于使用位运算符的web开发过程中遇到许多用例。

Although I grasp the concept of Bitwise Operators, I can't say that I have come across many use cases during the webdevelopment process at which I had to resort to using Bitwise Operators.


  • 请您使用位运算符?

  • 为什么要使用它?

  • 什么是一些示例使用案例?

请记住,这个问题是专门用于使用位运算符的网络语言。

Please remember that this question is specifically intended for use of Bitwise Operators in web languages.

推荐答案

我对位运算符的主要用途可能是相关的任何地方 - 再presenting一组标志。例如,你可能会在数据库中重新presenting一组安全权限用户的整数,并在你的web应用程序,你将不得不继续之前检查这些。

My main use for bitwise operators could be relevant anywhere - representing a set of flags. For instance, you might have an integer in the database representing a set of security permissions for a user, and in your web app you would have to check those before continuing.

这些往往只需要&放大器; | - 例如

Those tend to only require & and | - e.g.

if ((permissions & Permission.CreateUser) != 0)
{
    ...
}

Permission requiredPermission = Permission.CreateUser
                                | Permission.ChangePassword;

位的移动的运营商都在我的经验,经营的应用不太有用。

Bit shifting operators are less useful in "business" applications in my experience.

这篇关于何时web开发过程中使用位运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆