是打开或关闭的字节 [英] is the byte on or off
问题描述
亲爱的大师
我有一个问题,更多的是数学而不是Access。但是,我在访问中使用了它,并且可能有一个特定于访问的命令,我可以用它来实现我所需要的(如下所述)。 />
这是我的问题。我需要一个公式来告诉我任何数字
介于0到256之间,哪些字节是on
例如
>
000 ......没有字节打开
256 ...所有字节都打开
128 ...只有字节8被使用
我在VB中编写一个函数,在输入一个
数字和一个字节后返回true或false(例如F(128,8)返回true,F(129) ,1)返回true,
F(130,1)返回false,F(256,4)返回true,等等......)。
谢谢
- Nicolaas
" WindAndWaves" <交流**** @ ngaru.com>在消息中写道
新闻:CC ******************* @ news.xtra.co.nz ...亲爱的大师
我有一个问题,更多的是关于数学而不是Access。但是,我在访问中使用它,可能有一个特定于访问的命令,我可以使用
来实现我所需要的(如下所述)。
这是我的问题。我需要一个公式,告诉我任何数字在0到256之间,什么字节是打开
例如
000 ...没有字节是在256 ......所有字节都打开
128 ...只有字节8被使用
我在VB中编写一个函数,在输入之后返回true或false
数字和一个字节(例如F(128,8)返回true,F(129,1)返回true,
F(130,1)返回false,F(256,4)返回true,等等......)
谢谢
- Nicolaas
Nicolaas,
几个小点。我们通常将单个1'和0'位称为
而不是字节。所以:
000 ......没有比特在上面
128 ...这里我们会说第7位开启(从0开始,第8位)位 -
也被定义为2 ^ 7)
256 ...并非所有位都开启 - 255是
进一步:
F(256,4)不应该返回true
F(255,4)会返回true
VB按位运算符将完全满足您的需要:
私有函数F(J作为整数,K作为整数)作为布尔值
F = J和K
结束功能
Debug.Print F(128,8)
True
此致,
兰迪
很棒,谢谢兰迪。
亲爱的兰迪
我试过你的配方,但它似乎不起作用。我可以使用没有
的数学公式吗?
谢谢
- Nicolaas
PS下面的函数应该是1到8之间的数字,指向
位1到8,所以我修改如下:
函数F(A As Integer,B As Integer)As Boolean
B = B -1
F = A和B
结束函数
Dear Gurus
I have a question that is really more about maths than Access. However, I
am using it in access and may be there is an access specific command that I
may use to achieve what i need (as outlined below).
Here is my question. I need a formulae that tells me for any number
between 0 and 256 what bytes are "on"
for example
000 ... no bytes are on
256 ... all bytes are on
128 ... only byte 8 is engaged
I am writing a function in VB that returns true or false after you input a
number and a byte (e.g. F(128, 8) returns true, F(129,1) returns true,
F(130, 1) returns false, F(256, 4) returns true, etc...).
Thank you
- Nicolaas
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:CC*******************@news.xtra.co.nz...Dear Gurus
I have a question that is really more about maths than Access. However, I
am using it in access and may be there is an access specific command that I may use to achieve what i need (as outlined below).
Here is my question. I need a formulae that tells me for any number
between 0 and 256 what bytes are "on"
for example
000 ... no bytes are on
256 ... all bytes are on
128 ... only byte 8 is engaged
I am writing a function in VB that returns true or false after you input a
number and a byte (e.g. F(128, 8) returns true, F(129,1) returns true,
F(130, 1) returns false, F(256, 4) returns true, etc...).
Thank you
- Nicolaas
Nicolaas,
A couple of small points. We usually call the individual 1''s and 0'' bits
rather than bytes. So:
000 ... no bits are on
128 ... here we would say that bit 7 is on (starting from 0, the 8th bit -
also defined as 2^7 )
256 ... is not all bits on - 255 is
Further:
F(256, 4) should not return true
F(255, 4) would return true
The VB bitwise operator will do exactly what you need:
Private Function F(J As Integer, K As Integer) As Boolean
F = J And K
End Function
Debug.Print F(128, 8)
True
Regards,
Randy
Brilliant, thank you Randy.
Dear Randy
I tried your formula, but it does not seem to work. Is there no
mathematical formula that I can use?
Thank you
- Nicolaas
PS in the function below B should be a number between 1 and 8, pointing to
bit 1 to 8, so I amended it as follows:
Function F(A As Integer, B As Integer) As Boolean
B = B -1
F = A And B
End Function
这篇关于是打开或关闭的字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!