Java function equivalent to pack("v",int) in Perl/PHP

Asked

Viewed 77 times

0

I wonder if there is any function in Java equivalent to function pack("v",numero) of Perl and PHP.

In perl/php:

pack("v",numero) = unsigned short (always 16 bit, little endian byte order)

In Java:

?
  • This http://www.tutorialspoint.com/perl/perl_pack.htm ?

  • Yes, I wanted to know how I can generate the equivalent result in java.

  • Dude, in Java the guy short is Signed orderly big endian, Java 8 started to have some type support unsigned (through methods in Wrappers as Integer and Long). How would you like to store your converted number? What are you going to use it for? Guava has a Littleendiandataoutputstream able to write shorts for a stream little endian if that’s what you need.

  • Sockets. Thanks, solved the problem.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.