Home : J-Integra for .NET : HOWTO : Mapping Passing Byte Values from .NET to Java and from Java to .NET
Q31311 - HOWTO: Mapping Passing Byte Values from .NET to Java and from Java to .NET

Mapping Passing Byte Values from .NET to Java and from Java to .NET

 

Contents

  1. SYMPTOMS
  2. CAUSE
  3. RESOLUTION

SYMPTOMS

Byte values are incorrect when calling a Java method from a .NET client and calling a .NET method from a Java client.

CAUSE

The type byte in .NET and Java have different ranges. Java only has the signed type, byte, which ranges from -127..128. In .NET, there are two different types - signed and unsigned. The .NET unsigned type is byte and has a range of 0..255. The .NET signed type is sbyte and has a range of -127..128.

J-Integra for .NET currently maps the Java signed type byte (-127..128) onto the .NET unsigned type byte (0..255), which means that the user will need to perform conversions on the byte values received using J-Integra for .NET.

RESOLUTION

When receiving bytes from a Java client, a possible conversion routine in C# looks like this:

sbyte toSignedByte(byte b) {  return b < 128 ? (sbyte)b :(sbyte)(b - 256);}

When receiving bytes from .NET client, a possible conversion routine in Java looks like this:

int toUnsignedInt(byte b) {   return b > =0 ? b : (256 + b);}

Status

The above conversion routines may be incorporated into a future release of J-Integra for .NET so that they are no longer required to be coded by the developer.

Related Articles
No Related Articles Available.

Article Attachments
No Attachments Available.

Related External Links
No Related Links Available.
Help us improve this article...
What did you think of this article?

poor 
1
2
3
4
5
6
7
8
9
10

 excellent
Tell us why you rated the content this way. (optional)
 
Approved Comments...
No user comments available for this article.
Created on 6/23/2006.
Last Modified on 7/10/2006.
Last Modified by No Author Name Available!.
Article has been viewed 8550 times.
Rated 0 out of 10 based on 0 votes.
Print Article
Email Article