无符号整数问题? [英] Unsigned integer problem?

查看:91
本文介绍了无符号整数问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部


我必须读取四个字节的二进制数据,我需要使用

跟随函数来处理数据:


私函数BIT(ByVal Val As UInt32,ByVal BitNum As UInt32)As

UInt32

Dim displayMask As UInt32 = Convert .ToUInt32(1)


If(BitNum = Convert.ToUInt32(0))然后

If((Val和displayMask)= 1)然后

返回Convert.ToUInt32(1)

否则

返回Convert.ToUInt32(0)

结束如果

否则

Val = shiftRight(Val,BitNum)

如果((Val和displayMask)= 1)那么

返回Convert.ToUInt32(1)

否则

返回Convert.ToUInt32(0)

结束如果

结束If

结束功能


但是我得到的错误就像运营商和''或''=''没有为类型定义

''System.uint32"。


如何让它工作?

谢谢!

解决方案

当前版本的VB.Net将允许你声明无符号整数,但

实际上并不支持它们。

基本上没有定义用于处理它们的运算符。你不能添加,

减去,比较等等。

我的解决方案是暂时写所有函数必须处理无符号

整数在C#中并将其引用到VB中。

如果这不是你的选择,那么根据你的需要,你可能是b $ b能够使用BitFields,或者一个Bytes数组,或者将UInt32转换为Int64

(注意确保结果是正面符号并忽略

浪费了额外的32位)。 br />
我读过有关即将推出的VB.Net版本支持Unsigned

整数的传言。我真的希望是这样的。


Gerald


" barbara" < BA ********** @ yahoo.com>在消息中写道

news:69 ************************* @ posting.google.co m ... < blockquote class =post_quotes>所有

我必须读取四个字节的二进制数据,我需要使用
以下函数来处理数据:

私函数BIT(ByVal Val As UInt32,ByVal BitNum As UInt32)As
UInt32
Dim displayMask As UInt32 = Convert.ToUInt32(1)

If(BitNum) = Convert.ToUInt32(0))然后
如果((Val和displayMask)= 1)那么
返回Convert.ToUInt32(1)
否则
返回Convert.ToUInt32(0 )
结束如果
其他
Val = shiftRight(Val,BitNum)
如果((Val和displayMask)= 1)那么
返回Convert.ToUInt32(1)
其他
返回Convert.ToUInt32(0)
结束如果
结束如果
结束功能

但我错了或者像运营商和'或''=''没有为类型定义
''System.uint32"。

如何使它工作?

谢谢!



Echoed


-


OHM(特里伯恩斯)

。 。 。单手人。 。

" Cablewizard" <钙********* @ Yahoo.com>在消息中写道

新闻:OJ ************** @ TK2MSFTNGP12.phx.gbl ...

当前版本的VB .Net将允许你声明无符号整数,
但实际上并不支持它们。
基本上没有定义用于处理它们的运算符。你不能
加,减,比较等。
我的解决方案是暂时写入所有函数必须处理C#中的无符号整数并将其引入VB。
如果这不是你的选择,那么根据你的需要,你可以
能够使用BitFields或Bytes数组,或者将UInt32转换为
Int64(需要注意)关于确保结果是正面签名和
忽略浪费的额外32位)。
我已经读过传言即将推出的VB.Net版本将支持
无符号整数。我真的希望是这样的。

杰拉德

巴巴拉 < BA ********** @ yahoo.com>在消息中写道
新闻:69 ************************* @ posting.google.co m ...

所有

我必须读取四个字节的二进制数据,我需要使用
以下函数来处理数据:

私有函数BIT(ByVal Val As UInt32,ByVal BitNum As UInt32)As
UInt32
Dim displayMask As UInt32 = Convert.ToUInt32(1)

If(BitNum = Convert.ToUInt32 (0))然后
如果((Val和displayMask)= 1)那么
返回Convert.ToUInt32(1)
否则
返回Convert.ToUInt32(0)
结束如果
其他
Val = shiftRight(Val,BitNum)
如果((Val和displayMask)= 1)那么
返回Convert.ToUInt32(1)
否则
返回Convert.ToUInt32(0)
结束如果
结束如果
结束功能

但是我得到了错误li ke操作员和'或''=''没有为类型定义
''System.uint32"。

如何使其工作?

谢谢!




*" One Handed Man \(OHM - Terry Burns \)" < news.microsoft.com> scripsit:

Echoed




?!?


-

Herfried K. Wagner [MVP]

< URL:http://dotnet.mvps.org/>


Hi, all

I have to read a binary data which is four bytes and I need to use the
following function to deal with data:

Private Function BIT(ByVal Val As UInt32, ByVal BitNum As UInt32) As
UInt32
Dim displayMask As UInt32 = Convert.ToUInt32(1)

If (BitNum = Convert.ToUInt32(0)) Then
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
Else
Val = shiftRight(Val, BitNum)
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
End If
End Function

but I got error like "Operator ''And'' or ''='' is not defined for types
''System.uint32".

How to make it work?
Thanks!

解决方案

The current version of VB.Net will allow you to declare unsigned integers, but
really doesn''t support them.
There are basically no operators defined for working with them. You can''t add,
subtract, compare, etc.
My solution was to temporarily write all functions must deal with unsigned
integers in C# and reference that into VB.
If that isn''t an option for you, then depending upon your needs, you might be
able to use BitFields, or an array of Bytes, or cast the UInt32 to an Int64
(taking some care about making sure the result is signed positive and ignoring
the wasted additional 32 bits).
I have read rumors that the upcoming version of VB.Net will support Unsigned
Integers. I truly hope this is the case.

Gerald

"barbara" <ba**********@yahoo.com> wrote in message
news:69*************************@posting.google.co m...

Hi, all

I have to read a binary data which is four bytes and I need to use the
following function to deal with data:

Private Function BIT(ByVal Val As UInt32, ByVal BitNum As UInt32) As
UInt32
Dim displayMask As UInt32 = Convert.ToUInt32(1)

If (BitNum = Convert.ToUInt32(0)) Then
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
Else
Val = shiftRight(Val, BitNum)
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
End If
End Function

but I got error like "Operator ''And'' or ''='' is not defined for types
''System.uint32".

How to make it work?
Thanks!



Echoed

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Cablewizard" <Ca*********@Yahoo.com> wrote in message
news:OJ**************@TK2MSFTNGP12.phx.gbl...

The current version of VB.Net will allow you to declare unsigned integers, but really doesn''t support them.
There are basically no operators defined for working with them. You can''t add, subtract, compare, etc.
My solution was to temporarily write all functions must deal with unsigned
integers in C# and reference that into VB.
If that isn''t an option for you, then depending upon your needs, you might be able to use BitFields, or an array of Bytes, or cast the UInt32 to an Int64 (taking some care about making sure the result is signed positive and ignoring the wasted additional 32 bits).
I have read rumors that the upcoming version of VB.Net will support Unsigned Integers. I truly hope this is the case.

Gerald

"barbara" <ba**********@yahoo.com> wrote in message
news:69*************************@posting.google.co m...

Hi, all

I have to read a binary data which is four bytes and I need to use the
following function to deal with data:

Private Function BIT(ByVal Val As UInt32, ByVal BitNum As UInt32) As
UInt32
Dim displayMask As UInt32 = Convert.ToUInt32(1)

If (BitNum = Convert.ToUInt32(0)) Then
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
Else
Val = shiftRight(Val, BitNum)
If ((Val And displayMask) = 1) Then
Return Convert.ToUInt32(1)
Else
Return Convert.ToUInt32(0)
End If
End If
End Function

but I got error like "Operator ''And'' or ''='' is not defined for types
''System.uint32".

How to make it work?
Thanks!




* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:

Echoed



?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>


这篇关于无符号整数问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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