Need to convert a 16 byte array of bytes to 4 byte integer 
Author Message
 Need to convert a 16 byte array of bytes to 4 byte integer

I am getting a casting error when trying to store or convert a 16 byte
array of bytes to a 4 byte integer. The value of the 16 bytes is small
but I have a third party control which requires a 4 byte integer. The 16
bytes are coming from Recordset.Bookmark in Pervasive.SQL V8.
How would I go about converting the 16 bytes to a 4 byte integer?

Thanks,
   Lindy

*** Sent via Developersdex http://www.*-*-*.com/ ***
Don't just participate in USENET...get rewarded for it!



Sun, 21 Aug 2005 02:23:51 GMT  
 Need to convert a 16 byte array of bytes to 4 byte integer

Quote:
> I am getting a casting error when trying to store or convert a
> 16 byte array of bytes to a 4 byte integer. The value of the 16
> bytes is small but I have a third party control which requires a
> 4 byte integer. The 16 bytes are coming from Recordset.Bookmark
> in Pervasive.SQL V8. How would I go about converting the 16
> bytes to a 4 byte integer?

What happens to the remaining 12 bytes??

Armin



Sun, 21 Aug 2005 02:57:14 GMT  
 Need to convert a 16 byte array of bytes to 4 byte integer

Hi Armin,
   Thanks for your reply. I believe that all of the relevant data will
be contained in the first 4 bytes. Pervasive has changed how it returns
bookmarks from 4 bytes to 16 bytes. They claim that it speeds up the
process but when I test the values on an older version of Pervasive,
these values are small (e.g. 50, 51, 52).
   My problem is that when I run in Pervasive.SQL version 8, the
recordset bookmark returned is 16 bytes and so far I cannot figure out
how to read this value into anything other than an object. But once I
try to read the object, it has been set as a 16 byte array of bytes so I
still can't do anything.
   Any ideas how I can get those first 4 bytes into a 4 byte integer? (I
need to figure out the value of the full 4 bytes, not just the
individual values).

   Thanks,
   Lindy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 21 Aug 2005 03:14:19 GMT  
 Need to convert a 16 byte array of bytes to 4 byte integer

Quote:

> Hi Armin,
>    Thanks for your reply. I believe that all of the relevant
> data will
> be contained in the first 4 bytes. Pervasive has changed how it
> returns bookmarks from 4 bytes to 16 bytes. They claim that it
> speeds up the process but when I test the values on an older
> version of Pervasive, these values are small (e.g. 50, 51, 52).
>    My problem is that when I run in Pervasive.SQL version 8, the
> recordset bookmark returned is 16 bytes and so far I cannot
> figure out how to read this value into anything other than an
> object. But once I try to read the object, it has been set as a
> 16 byte array of bytes so I still can't do anything.
>    Any ideas how I can get those first 4 bytes into a 4 byte
> integer? (I
> need to figure out the value of the full 4 bytes, not just the
> individual values).

dim b as byte()
dim i as integer
'...
i = System.BitConverter.ToInt32(b, 0)

It's your decision whether to drop the rest. :)

Armin



Sun, 21 Aug 2005 03:37:46 GMT  
 Need to convert a 16 byte array of bytes to 4 byte integer
Hi Armin,
   Thanks for your suggestion! It worked great. Now I have a problem
going the other direction.
   I now have an integer (4 bytes) with a value for example of 83,000
and I need to store this back into the Recordset.Bookmark which is a 16
byte array of bytes.
   What do you suggest? I tried a couple of the BitConverter.GetBytes
and I also tried storing the value of the 4 byte into directly into the
16 byte bookmark and neither of these worked.

   Thanks,
   Lindy

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Sun, 21 Aug 2005 07:04:43 GMT  
 Need to convert a 16 byte array of bytes to 4 byte integer

Quote:
> Hi Armin,
>    Thanks for your suggestion! It worked great. Now I have a
> problem
> going the other direction.
>    I now have an integer (4 bytes) with a value for example of
> 83,000
> and I need to store this back into the Recordset.Bookmark which
> is a 16 byte array of bytes.
>    What do you suggest? I tried a couple of the
> BitConverter.GetBytes
> and I also tried storing the value of the 4 byte into directly
> into the 16 byte bookmark and neither of these worked.

dim b16(15) as byte
dim b4() as byte

b4 = System.BitConverter.GetBytes(MyInt)
array.copy b4, b16, 4

Instead of the last line, this might be faster:
      b16(0) = b4(0)
      b16(1) = b4(1)
      b16(2) = b4(2)
      b16(3) = b4(3)

Armin



Sun, 21 Aug 2005 07:36:18 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Copy bytes from an Integer to a location of bytes array

2. Converting integers and long integers to byte arrays

3. Need help on converting 2-byte signed to 2-byte unsigned

4. Convert integers and strings to byte array

5. Convert byte-array to integer or real?

6. Converting integer (or long) data type to array of bytes

7. How to convert 4 byte date to 8 byte date

8. Need help converting an ip to an integer in host byte order

9. VB6 Byte Array to Byte()

10. Problem with the length of byte arrays and the length (in bytes) of diffrent datatypes

11. Put Byte Array Descriptor Length = 12 bytes?

12. Converting string array to byte array

 

 
Powered by phpBB® Forum Software