Efficient method to convert 4 bytes in one Int32 signed integer 
Author Message
 Efficient method to convert 4 bytes in one Int32 signed integer

I have 4 byte and have to convert (using VB.NET) in an integer number
Int32.
Moreover with this limitation:
- The first bytes is the highest byte, the last byte is the lowest
byte
- The HighNibble of the first byte should be eliminated
- the LowNibble of the last byte should be eliminated

4 Byte:
[HNibble1 LNibble1]+
[HNibble2 LNibble2]+
[HNibble3 LNibble3]+
[HNibble4 LNibble4]

Int32 signed number:
[LNibble1 HNibble2 LNibble2 HNibble3 LNibble3 HNibble4]

Working with string would be an easy way to do that, but not efficient
in huge data loops.

May be in C some binary functions would help, but what in VB.NET?

Thank you for your help.

Regards.



Tue, 28 Dec 2004 19:07:01 GMT  
 Efficient method to convert 4 bytes in one Int32 signed integer
There are no bit shift operators in VB .NET like there are in other
languages.  In VB .NET you might try simulate shifts by multiplying/dividing
with powers of 2.

Mohan & Corneliu (VB)

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> I have 4 byte and have to convert (using VB.NET) in an integer number
> Int32.
> Moreover with this limitation:
> - The first bytes is the highest byte, the last byte is the lowest
> byte
> - The HighNibble of the first byte should be eliminated
> - the LowNibble of the last byte should be eliminated

> 4 Byte:
> [HNibble1 LNibble1]+
> [HNibble2 LNibble2]+
> [HNibble3 LNibble3]+
> [HNibble4 LNibble4]

> Int32 signed number:
> [LNibble1 HNibble2 LNibble2 HNibble3 LNibble3 HNibble4]

> Working with string would be an easy way to do that, but not efficient
> in huge data loops.

> May be in C some binary functions would help, but what in VB.NET?

> Thank you for your help.

> Regards.



Wed, 29 Dec 2004 04:43:13 GMT  
 Efficient method to convert 4 bytes in one Int32 signed integer
Ingo,

Quote:
>May be in C some binary functions would help, but what in VB.NET?

If I understand your requirements correctly,

1) Use Array.Reverse on your byte array to reverse the order.
2) Use BitConverter.ToInt32() to convert to an Integer.
3) Mask out the high nibble using And &H0FFFFFFF
4) "Shift" out the low nibble by dividing by 16.

Mattias

===
Mattias Sj?gren (VB MVP)

http://www.msjogren.net/dotnet/



Wed, 29 Dec 2004 06:32:42 GMT  
 Efficient method to convert 4 bytes in one Int32 signed integer

The NDP Framework provides the System.Collections.Specialized.BitVector32 class which provides the functionality that you need:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemcollectionsspecializedbitvector32classtopic.htm

Cameron, John, and Jeanie

--
This posting is provided "AS IS" with no warranties, and confers no rights.


Quote:
> There are no bit shift operators in VB .NET like there are in other
> languages.  In VB .NET you might try simulate shifts by multiplying/dividing
> with powers of 2.

> Mohan & Corneliu (VB)

> --
> This posting is provided "AS IS" with no warranties, and confers no rights.



> > I have 4 byte and have to convert (using VB.NET) in an integer number
> > Int32.
> > Moreover with this limitation:
> > - The first bytes is the highest byte, the last byte is the lowest
> > byte
> > - The HighNibble of the first byte should be eliminated
> > - the LowNibble of the last byte should be eliminated

> > 4 Byte:
> > [HNibble1 LNibble1]+
> > [HNibble2 LNibble2]+
> > [HNibble3 LNibble3]+
> > [HNibble4 LNibble4]

> > Int32 signed number:
> > [LNibble1 HNibble2 LNibble2 HNibble3 LNibble3 HNibble4]

> > Working with string would be an easy way to do that, but not efficient
> > in huge data loops.

> > May be in C some binary functions would help, but what in VB.NET?

> > Thank you for your help.

> > Regards.



Sat, 01 Jan 2005 03:40:26 GMT  
 Efficient method to convert 4 bytes in one Int32 signed integer
On Mon, 15 Jul 2002 12:40:26 -0700, "VBDotNet Team [MS]"

Quote:

>The NDP Framework provides the System.Collections.Specialized.BitVector32 class which provides the functionality that you need:
>ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemcollectionsspecializedbitvector32classtopic.htm

Thank you very much!
This class seems the right one.

Regards,
Ingo



Sat, 01 Jan 2005 17:55:29 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Need to convert a 16 byte array of bytes to 4 byte integer

2. Converting integers and long integers to byte arrays

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

4. Signed Integer to Byte Array HELP

5. Efficient converting from byte-string to word-string

6. Convert integers and strings to byte array

7. Convert byte-array to integer or real?

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

9. How to convert bytes to integers ?

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

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

12. 4 Bytes convert to one single

 

 
Powered by phpBB® Forum Software