How do we do arithmetic on UInts?

  • Thread starter Thread starter Rob Richardson
  • Start date Start date
R

Rob Richardson

Greetings!

I am trying to read a file at the byte level (because the vendor does not
provide a tool that exposes the ifnormation I need). So, I need to read
offsets from within the file itself. For example, I know that the offset of
the first field I need to read is contained in bytes 5 through 8 of the
file. So I need to handle those bytes as an unsigned 32-bit number -- a
UInt32. Once I get to the start of the field, I need to move 12 more bytes
to get the first piece of data I need.

But the UInt32 structure does not support any type of arithmetic!

How am I supposed to add 12 to a UInt32?

I understand Whidbey will let us do this (along with any other true operator
overloading we want). I can't wait!

Rob
 
* "Rob Richardson said:
I am trying to read a file at the byte level (because the vendor does not
provide a tool that exposes the ifnormation I need). So, I need to read
offsets from within the file itself. For example, I know that the offset of
the first field I need to read is contained in bytes 5 through 8 of the
file. So I need to handle those bytes as an unsigned 32-bit number -- a
UInt32. Once I get to the start of the field, I need to move 12 more bytes
to get the first piece of data I need.

\\\
Dim ui As UInt32 = ...
Dim i As Integer = Convert.ToInt32(ui)
i += 5
///
 
Rob,

as long as you don't have to do anything with an uint32 but reading it and
adding a value, simply convert the uint32 into a Long using the Convert
class. (Convert.ToInt64(uintVar)). That should do the trick.
BTW: You could also use a Long to begin with. If you have the four bytes
containing the value, just use

Dim longvalue as long=byte1+byte2*2^8+byte3*2^16+byte4*2^24

to get the actual value you need (assuming, that byte1 really contains the
low byte).

Klaus
 
Back
Top