Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2005

Tip: Looking for answers? Try searching our database.

Datagram byte[] values over 2^7-1

Thread view: 
mswope - 20 Apr 2005 17:27 GMT
Howdy!
I'm trying to construct an UDP datagram packet with an array of values.  Two
of the values should be 0xC1 and 0xEA (as captured on the wire).
If I build a byte array with these values, I get a loss of precision
warning.

How can I send values larger than 2^7-1 in a datagram packet array?

Thanks,
mas
Thomas Fritsch - 20 Apr 2005 18:15 GMT
> Howdy!
> I'm trying to construct an UDP datagram packet with an array of values.  Two
[quoted text clipped - 6 lines]
> Thanks,
> mas

Use negative byte values. Or use type-casts, for example:
  (byte) 0xC1
Remember: the Java 'byte' is signed, in the range from -128 to +127.

Signature

"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')

mswope - 20 Apr 2005 20:16 GMT
>> Howdy!
>> I'm trying to construct an UDP datagram packet with an array of values.
[quoted text clipped - 10 lines]
>   (byte) 0xC1
> Remember: the Java 'byte' is signed, in the range from -128 to +127.

Thomas,
I do remember that 'byte' is signed, thus my question.  I used type-casting
per each affected element of the array and
it worked.
Thank you!

mas
Boudewijn Dijkstra - 20 Apr 2005 22:35 GMT
>>> Howdy!
>>> I'm trying to construct an UDP datagram packet with an array of values.
[quoted text clipped - 15 lines]
> per each affected element of the array and
> it worked.

Signed or unsigned, it will preserve values in any 256-sized range, including
0..255 and -128..127.

Well, as long as you remember which range it is.  ;)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.