外行人的位域是什么? [英] What is a bit field in layman's terms?

查看:25
本文介绍了外行人的位域是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我外行的位域是什么?我正在做 PHP 调试课程,讲师经常使用该术语.这是在 PHP 错误报告的上下文中.

Can anyone tell me what a bit field is in layman's terms? I am doing a PHP course in debugging and the instructor is using that term a lot. This is in the context of PHP error reporting.

这是抄录中的引述:

错误报告用整数设置错误报告级别通常通过命名常量表示位域.经过默认情况下,PHP 报告除 E_NOTICE 和之前版本的所有内容到 PHP 5.4,也不包括 E_STRICT.

Error reporting sets the error reporting level with an integer representing a bit field normally through a named constant. By default, PHP reports everything except E_NOTICE and for versions prior to PHP 5.4, also excluding E_STRICT.

我认为作为一个有抱负的程序员,了解我的行业术语很重要:)

I think it's important as an aspiring programmer that I understand the nomenclature of my trade :)

感谢您的帮助!

注意:我已经尝试过维基百科...

Note: I already made an attempt at wikipedia...

推荐答案

我们需要从一点点开始.位将采用两个值——零或一.按照惯例,零也被称为假,而一被称为真.

We need to start out with what is a bit. A bit will take two values -- a zero or a one. By convention, a zero is also referred as false while a one is referred to as true.

一个位域就是几个位.

我将在这里通过描述两种常见的位组织——字符和单词来离题.

I'll digress here by discribing to two common organization of bits -- characters and words.

在过去,PC 出现的字符是 8 位,字是 32 位.今天,字正在转向 64 位字.字符正在移动到 16 位.

In the old days at the time the pc came out characters where eight bits and words were 32 bits. Today, words are moving to 64 bit words. Characters are moving to 16 bits.

表示位域的整数

我不知道 PHP 是如何划分整数的,但这就是想法.基本上,如果您在位级别查看整数,您会发现一些具有某种意义的模式.

I do not know PHP how is dividing out the integer, but this is the idea. Basically, if you looked at the integer at the bit level you would find some patterns that have some meaning.

您需要了解十六进制和 2 的幂才能更清楚地了解这一点.

You need to understand hex and the powers of 2 to make more sense of this.

a 32 bit integer would be
0000 0000  0000 0000  0000 0000  0000 0000  

Putting in two bit fields...
0000 0000  0000 0000  0000 0000  AAAA BBBB 

从位中查看整数,您可以找到两个字段 A &B 每 4 位宽.

Looking at the integer from the bits you could find two fields A & B each 4 bits wide.

AAAA 的十六进制值可能是 1100 或 CBBBB 的十六进制值可能是 0111 或 7.

AAAA might have the value of 1100 or C in hex BBBB might have the value of 0111 or 7 in hex.

整数的十六进制值为 C7 或十进制值为 199.

the integer would have a value of C7 in hex or 199 in decimal.

因此,使用位域查看整数 199 时会有不同的外观.

So, the integer 199 when looked at with bit fields would have a different look.

罗伯特

这篇关于外行人的位域是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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