By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,569 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,569 IT Pros & Developers. It's quick & easy.

Bit-wise operations against UInt vars

P: n/a
How can I do a bit-wise operation on a UInt, such as:

dim x as UInt32

x = x And &H80

It says the "And operator isn't defined for UInt32"

But why not? And is there a work-around?

(yes, I must use unsigned-integers...I'm trying to write routines to convert
between IBM<->IEEE floating point, and I must access the floats as if they're
unsigned integers)

Thanks!

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
"David" <Da***@discussions.microsoft.com> schrieb:
How can I do a bit-wise operation on a UInt, such as:

dim x as UInt32

x = x And &H80

It says the "And operator isn't defined for UInt32"


Unsigned integers are not CLS-compliant and thus not supported by VB.NET.
You can either wait for VB 2005 or write the code in C#.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #2

P: n/a

"David" <Da***@discussions.microsoft.com> wrote in message
news:20**********************************@microsof t.com...
How can I do a bit-wise operation on a UInt, such as:

dim x as UInt32

x = x And &H80

It says the "And operator isn't defined for UInt32"

But why not? And is there a work-around?

(yes, I must use unsigned-integers...I'm trying to write routines to convert between IBM<->IEEE floating point, and I must access the floats as if they're unsigned integers)

Thanks!


In addition to Herfried's comments...
Writing the method in C# is the "easiest" method in the short term (until VB
2005).
However, having done the same thing for VAX / PDP11 <-> IEEE, I can say from
experience that it can be done with signed Integers. I used primarily byte
arrays, but also a signed Int64 for convenience. Since the top bit of the
float is the sign bit, just store it's value for later use, then clear it.
The rest fits nicely into an Int64, or easily broken down into smaller
Integer types. If all else fails, there is still the byte array.
Another thing that might cause frustration is bit shifting. If you don't
have VB 2003, then I don't think you have native support for the shift
operators. In this case, "I" would at least mix in some C# to make things
easier. If C# isn't your thing, it is still do-able in VB, just less fun.

Gerald
Nov 21 '05 #3

P: n/a
Gerald,

I went ahead a began writing my routine in C# (maybe after VB 2005 is out
I'll rewrite it)...

But I'll be darned if I can get IEEE->IBM to work correctly! I started with
sample code I found at SAS, but after a couple of days staring at it and
trying to port it, I'm beginning to wonder if the sample code really works
(or whether its just user-error).

Do you know of sample code that goes from IBM float to IEEE float? 32 bit
(single precision) would be preferred, but 64 bit would also be OK. And the
language doesn't really matter (although C or similar would be best).

Or if you don't know of code, maybe just the underlying algorithm?

Thanks,

David


"Gerald Hernandez" wrote:
having done the same thing for VAX / PDP11 <-> IEEE


Nov 21 '05 #4

P: n/a

"David" <Da***@discussions.microsoft.com> wrote in message
news:22**********************************@microsof t.com...
Gerald,

I went ahead a began writing my routine in C# (maybe after VB 2005 is out
I'll rewrite it)...

But I'll be darned if I can get IEEE->IBM to work correctly! I started with sample code I found at SAS, but after a couple of days staring at it and
trying to port it, I'm beginning to wonder if the sample code really works
(or whether its just user-error).

Do you know of sample code that goes from IBM float to IEEE float? 32 bit
(single precision) would be preferred, but 64 bit would also be OK. And the language doesn't really matter (although C or similar would be best).

Or if you don't know of code, maybe just the underlying algorithm?

Thanks,

David


David,

Which IBM Float specifically are you needing, as there are a couple
different definitions?
I don't recall running across a sample for IBM floats, well, no "good"
example for any float conversions for that matter. I had to mull it over
myself bit-by-bit. So I feel your pain. Bit-Twiddling Floating Point values
is quite an experience. I now have a much greater understanding, respect,
and healthy fear of floats. :-)
Do you know the Byte order?
Since most floating point definitions share the same common concepts, I
suspect it would be possible to alter my VAX<-> IEEE code to work with IBM.
If you can point me to an /exact/ definition of what you are working with, I
can see if this is possible.

Gerald
Nov 21 '05 #5

P: n/a
Hmm... It appears that the IBM format is more different from VAX than I
previousely thought.
Interestingly, the solution is actually easier. I found this which I think
should get you back on track.
http://support.microsoft.com/default...;EN-US;q235856

Gerald
Nov 21 '05 #6

P: n/a
Gerald,

Yes, that KB article is helpful, but it goes in the wrong direction
(IBM-to-IEEE).
I needed IEEE-to-IBM.

Anyway, this morning I had one of those conceptual breakthroughs, and
finally figured-out why the SAS example
(http://support.sas.com/techsup/technote/ts140.html) wasn't working... it was
my error during porting their example to C#.

So I've now got a C# function that does IEEE-to-IBM (in fact, I used the VB
code from the MSDN article to round-trip test my function, and it looks like
it's working OK).

Thanks for the help!

(I might post my function once it's been tested a bit more)

David

"Gerald Hernandez" wrote:
I found this which I think
should get you back on track.
http://support.microsoft.com/default...;EN-US;q235856

Gerald

Nov 21 '05 #7

P: n/a

"David" <Da***@discussions.microsoft.com> wrote in message
news:9C**********************************@microsof t.com...
Gerald,
<Snip...>
(I might post my function once it's been tested a bit more)

David


Glad you got it worked out. Yeah, posting the function might be a good idea.
As you have found, this can be a painful experience and there isn't a whole
heck of a lot of good examples out there. I read a little bit from the link
you sent and had to laugh when I read the following line:
"Not included is VAX, which uses a different floating point representation
than either IBM mainframe or IEEE."

I think maybe I should generalize my VAX<-> IEEE code and post that as well.
Someone might find it helpful.

Gerald
Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.