Bit-wise operations against UInt vars

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
David said:
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#.
 
David said:
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
 
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 said:
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
 
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
 
David said:
(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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top