473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Unsigned integer problem?

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!
Nov 20 '05 #1
20 4647
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!

Nov 20 '05 #2
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!


Nov 20 '05 #3
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Echoed


?!?

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
I have read rumors that the upcoming version of VB.Net will support Unsigned
Integers. I truly hope this is the case.


They will be supported, but that doesn't make them more CLS compliant.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
It means 'I echo you' ( Agree )

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Echoed


?!?

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

Nov 20 '05 #6
True, would not be compliant. One thing that really got me excited about the
announcement of the CLR was unified variable handling. I saw a list at that time
which included UInt's. Like many VB programmers, I frequently have need to
interoperate with C. And we all know what a mess passing variables can be. That,
and I frequently need to work with files and such that use UInt's extensively.
When VB.Net was finally released, I jumped in with both feet to try to convert
all my stuff over so I could use them. Had a rude awakening. I understand that
maybe UInt's "should" be phased out. However, I personally think that part of
the standard was shortsighted. There is a whole lot of data out there that uses
them. And when you just need that extra bit, sure is a big waste to double your
file and memory size.

Besides, would this be the first time that MS tried to set down a standard, then
violate their own standard, then provide a way around the standard? heh, just
poking fun.

Gerald

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
I have read rumors that the upcoming version of VB.Net will support Unsigned
Integers. I truly hope this is the case.


They will be supported, but that doesn't make them more CLS compliant.

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

Nov 20 '05 #7
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
True, would not be compliant. One thing that really got me excited about the
announcement of the CLR was unified variable handling. I saw a list at that time
which included UInt's. Like many VB programmers, I frequently have need to
interoperate with C. And we all know what a mess passing variables can be. That,
and I frequently need to work with files and such that use UInt's extensively.
When VB.Net was finally released, I jumped in with both feet to try to convert
all my stuff over so I could use them. Had a rude awakening. I understand that
maybe UInt's "should" be phased out. However, I personally think that part of
the standard was shortsighted. There is a whole lot of data out there that uses
them. And when you just need that extra bit, sure is a big waste to double your
file and memory size.
Mhm... I do not see many reasons for not adding them to the CLS too.
Nevertheless, it's the /Common/ Language Specification. Currently
unsigned integers are mostly used in p/invoke and interop scenarios that
are hardly ever CLS compliant.
Besides, would this be the first time that MS tried to set down a standard, then
violate their own standard, then provide a way around the standard? heh, just
poking fun.


It's a specification, no law ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #8
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
It means 'I echo you' ( Agree )


OK ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #9
Agreed. Bring on the next release. Can't wait for this and operator overloading
in VB.
Wahoo! :D

Gerald

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "Cablewizard" <Ca*********@Yahoo.com> scripsit:
True, would not be compliant. One thing that really got me excited about the
announcement of the CLR was unified variable handling. I saw a list at that time which included UInt's. Like many VB programmers, I frequently have need to
interoperate with C. And we all know what a mess passing variables can be. That, and I frequently need to work with files and such that use UInt's extensively. When VB.Net was finally released, I jumped in with both feet to try to convert all my stuff over so I could use them. Had a rude awakening. I understand that maybe UInt's "should" be phased out. However, I personally think that part of the standard was shortsighted. There is a whole lot of data out there that uses them. And when you just need that extra bit, sure is a big waste to double your file and memory size.


Mhm... I do not see many reasons for not adding them to the CLS too.
Nevertheless, it's the /Common/ Language Specification. Currently
unsigned integers are mostly used in p/invoke and interop scenarios that
are hardly ever CLS compliant.
Besides, would this be the first time that MS tried to set down a standard, then violate their own standard, then provide a way around the standard? heh, just poking fun.


It's a specification, no law ;-).

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

Nov 20 '05 #10
Hi Terry,

As far as I know, there are no mountains in the Thames Valley, echos comes
here in this newsgroups mostly from Austria, (for non Europeans who read
this, one of the EU countries with the most and highest mountains)

:-)

Cor

Nov 20 '05 #11
Yes, but I think the UKIP ( UK Independent Party ) will remove us from
Europe soon, so when I said that I was talking into a bucket.

;-)

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:Ou**************@TK2MSFTNGP10.phx.gbl...
Hi Terry,

As far as I know, there are no mountains in the Thames Valley, echos comes
here in this newsgroups mostly from Austria, (for non Europeans who read
this, one of the EU countries with the most and highest mountains)

:-)

Cor

Nov 20 '05 #12
Hi, Gerald,

I'd like to take the option which is writing all functions deal with
unsigned integers in C# and reference them into VB. But I am new to
vb.net and C#. Could you please give me some detail instructions about
how to make functions in C# and reference to VB.net?

Thank you so much in advance!

Barbara

"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!

Nov 20 '05 #13
Create a C# Class Library and add a class to it which contains your member
function. The Syntax is of course different to VB for example

Dim A as Int32 would be something like

Int32 A

To test the functionality. Add a reference to the Dll and then import the
namespace into the VB project, then you can reference the Function.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"barbara" <ba**********@yahoo.com> wrote in message
news:69*************************@posting.google.co m...
Hi, Gerald,

I'd like to take the option which is writing all functions deal with
unsigned integers in C# and reference them into VB. But I am new to
vb.net and C#. Could you please give me some detail instructions about
how to make functions in C# and reference to VB.net?

Thank you so much in advance!

Barbara

"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!

Nov 20 '05 #14
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Create a C# Class Library and add a class to it which contains your member
function. The Syntax is of course different to VB for example

Dim A as Int32 would be something like

Int32 A

To test the functionality. Add a reference to the Dll and then import the
namespace into the VB project, then you can reference the Function.


ACK. Nevertheless, I would not use UInts if possible.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #15
I completely agree. Where possible avoid it, however, some hardware uses
UInts in its registers, so it is a requirement from time to time.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Create a C# Class Library and add a class to it which contains your member function. The Syntax is of course different to VB for example

Dim A as Int32 would be something like

Int32 A

To test the functionality. Add a reference to the Dll and then import the namespace into the VB project, then you can reference the Function.


ACK. Nevertheless, I would not use UInts if possible.

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

Nov 20 '05 #16
Hmmm....
If you are not familiar with C#, then I might recommend one of the other methods
of dealing with these.
While UInts certainly have their place, I agree with Herfried, IF possible don't
keep them as UInts.
Even if you implement certain functionality in C# to deal with them, you are
better off not passing UInts back to VB.
Since I really do not know what your requirements are, there is limited
additional info I can provide.

Gerald

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2j*************@uni-berlin.de...
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
Create a C# Class Library and add a class to it which contains your member
function. The Syntax is of course different to VB for example

Dim A as Int32 would be something like

Int32 A

To test the functionality. Add a reference to the Dll and then import the
namespace into the VB project, then you can reference the Function.


ACK. Nevertheless, I would not use UInts if possible.

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

Nov 20 '05 #17
* "One Handed Man \( OHM - Terry Burns \)" <news.microsoft.com> scripsit:
I completely agree. Where possible avoid it, however, some hardware uses
UInts in its registers, so it is a requirement from time to time.


My post was a little bit unclear. I wanted to say: Don't use unsigned
integers in interfaces/methods/... that are visible to the "consumer" of
a component. Using them inside the implementation is IMO no problem and
sometimes there is no way around that.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #18
> Currently unsigned integers are mostly used in p/invoke and interop
scenarios that
are hardly ever CLS compliant.


Huh? Unsigned integers are also frequently used when talking to HARDWARE,
both in terms of simple bit manipulation as well as data acquisition.
Several times I've been frustrated that my "modern" computer language of
choice can't do simple things like count, add, and subtract without enormous
amount extra work on my part.

PLEASE add full unsigned integer support EVERYWHERE!

Sigh...

--George
Nov 20 '05 #19
I said something similar further up this post, take a look.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"George Yefchak" <ge****@yefchak.com> wrote in message
news:10***************@emperor.labs.agilent.com...
Currently unsigned integers are mostly used in p/invoke and interop scenarios that
are hardly ever CLS compliant.


Huh? Unsigned integers are also frequently used when talking to HARDWARE,
both in terms of simple bit manipulation as well as data acquisition.
Several times I've been frustrated that my "modern" computer language of
choice can't do simple things like count, add, and subtract without

enormous amount extra work on my part.

PLEASE add full unsigned integer support EVERYWHERE!

Sigh...

--George

Nov 20 '05 #20
* "George Yefchak" <ge****@yefchak.com> scripsit:
Currently unsigned integers are mostly used in p/invoke and interop
scenarios that
are hardly ever CLS compliant.
Huh? Unsigned integers are also frequently used when talking to HARDWARE,
both in terms of simple bit manipulation as well as data acquisition.
Several times I've been frustrated that my "modern" computer language of
choice can't do simple things like count, add, and subtract without enormous
amount extra work on my part.


Full ACK. Unsigned types are not useless.
PLEASE add full unsigned integer support EVERYWHERE!


This support will be added in VB 2005.

Notice that this won't make unsigned integers more CLS compliant.
Consequently, it's not goof to use them in the "interfaces" of a class
library that can be seen by other apps using this library.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

96
by: John Harrison | last post by:
I knew that unsigned integral data types were the cause of scads of mostly spurious warning messages, but I didn't realise that they were a security risk too (see here...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
9
by: luke | last post by:
Hi everybody, please, can someone explain me this behaviour. I have the following piece of code: long long ll; unsigned int i = 2; ll = -1 * i; printf("%lld\n", ll);
4
by: techie | last post by:
I have defined a number of unsigned integer types as follows: typedef unsigned char uint8; typedef unsigned short uint16; typedef unsigned int uint32; typedfe long long uint64; Is it...
3
by: wenmang | last post by:
Hi, I encountered a problem involving storage of unsigned long long. The requirement of incoming data field is an unsigned 64-bit integer, but on our system, due to lack of support of 64-bit...
10
by: Jim Langston | last post by:
Is the following well defined? size_t IntVal = 65537; unsigned short Length; if ( IntVal static_cast<unsigned short>( -1 ) ) { std::cout << "Value too long to fit in a short" << std::endl;...
24
by: Paulo Matos | last post by:
Hello, Is it safe to assume a size_t is an unsigned long? (is it forced by the standard?) Thank you, Paulo Matos
7
by: somenath | last post by:
Hi All, I am trying to undestand "Type Conversions" from K&R book.I am not able to understand the bellow mentioned text "Conversion rules are more complicated when unsigned operands are...
12
by: Martin Wells | last post by:
I'm trying to come up with a fully-portable macro for supplying memset with an unsigned char rather than an int. I'm going to think out loud as I go along. . . I'll take a sample system before I...
7
by: edsunder | last post by:
I'm making a "wrapper" for an unmanaged DLL (written, I'm fairly certain in C). I have a c++ "wrapper" that I'm trying to convert to VB.net. I've got most of the program working, but I've hit a brick...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.