Converter int para byte em java
Asked 5 years, 2 months ago. Active 2 years, 2 months ago. Viewed 9k times. BufferOverflowException without detail message. As for me code is valid. What is wrong? Improve this question. Valentine Zakharenko. Valentine Zakharenko Valentine Zakharenko 2, 1 1 gold badge 17 17 silver badges 41 41 bronze badges. At which line do you get the error? Add a comment. Active Oldest Votes. You forgot to flip your buffer after putting data in.
Improve this answer. Kayaman Kayaman A similar answer which doesn't require calling flip. Peter Lawrey Peter Lawrey k 73 73 gold badges silver badges bronze badges. Similar to your own solution but a bit more concise, the result is directly in the byte array. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. In below example, we have iterate of all the elements from array, convert it to a byte array and prepare final byte array.
Similarly when we converting byte array to int array, first we need to calculate the length of an array. Prepare four bytes chunk and convert it to integer and store it in an array. In this article we have discussed various techniques of converting byte array to int, int to byte array, int array to byte array and byte array to int array using ByteBuffer,DataInputStream,DataOutputStream and some custom logic.
Your email address will not be published. Table of Contents 1. Overview 2. Conclusion Was this post helpful? Was this post helpful? Let us know if you liked the post. Yes No Tags: int-to-byte-array , java , java Java Developer Zone. JavaDeveloperZone is a group of innovative software developers.
Feel free to ask any questions and suggestions. Always have space for improvement! Feel free to Contact us for any software development services.
0コメント