• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

byte array

 
Allan Cheong
Ranch Hand
Posts: 71
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Are there any methods to convert the value of primitive data type to byte[]? Let's say, converting an int to byte[] will return byte[].length == 4, short to byte[] will return byte[].length == 2 and so on.

Is it possible doing it without using NIO?

Regards,
Allan Cheong
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allan Cheong wrote:Is it possible doing it without using NIO?


And the reason you don't want to use the ByteBuffer class is ... ??

Henry
 
Allan Cheong
Ranch Hand
Posts: 71
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing SCJD assignment. NIO not allowed.
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Allan Cheong wrote:I am doing SCJD assignment. NIO not allowed.


Then you are back to basics... For each of the four bytes, shift the bits into place, AND out the other bits, and assign (cast).

Henry
 
Allan Cheong
Ranch Hand
Posts: 71
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic