Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

byte array  RSS feed

 
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
 
author
Sheriff
Posts: 23568
138
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
Sheriff
Posts: 23568
138
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
Boost this thread!