Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8889425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:15:35+00:00 2026-06-14T22:15:35+00:00

For my project I have to convert an integer into byte array and byte

  • 0

For my project I have to convert an integer into byte array and byte array back to integer.
I did the below code but it is not working

    int temp=200;

    byte[] tempbyte= new byte[4];

String s= String.valueOf(temp);
tempbyte= s.getBytes(); // integer to byte array conversion

String s2 = String.valueOf(ByteBuffer.wrap(tempbyte).getInt());

int temp2 = Integer.parseInt(s2); // byte array to integer conversion

System.out.println("the value of temp2 = "+temp2);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:15:37+00:00Added an answer on June 14, 2026 at 10:15 pm

    Theses are functions I’ve made years ago that could help you :

    public static float byteArrayToFloat(byte[] p_bArray)
    {
        int nValue;
    
        nValue = (0xFF & p_bArray[0]);
        nValue = nValue | ((0xFF & p_bArray[1]) << 8);
        nValue = nValue | ((0xFF & p_bArray[2]) << 16);
        nValue = nValue | ((0xFF & p_bArray[3]) << 24);
    
        float fValue = Float.intBitsToFloat(nValue);
    
        return fValue;
    }
    
    public static byte[] floatToByteArray(float p_fValue)
    {
        byte [] bArray = new byte[4];
        int nValue;
    
        nValue = Float.floatToIntBits(p_fValue);
    
        bArray[0] = (byte)nValue;
        bArray[1] = (byte)(nValue >> 8);
        bArray[2] = (byte)(nValue >> 16);
        bArray[3] = (byte)(nValue >> 24);
    
        return bArray;
    }
    
    public static double byteArrayToDouble(byte[] p_bArray)
    {
        long lValue;
    
        lValue = (long)p_bArray[0] & 0xFF;
        lValue = lValue | (((long)p_bArray[1] & 0xFF) << 8);
        lValue = lValue | (((long)p_bArray[2] & 0xFF) << 16);
        lValue = lValue | (((long)p_bArray[3] & 0xFF) << 24);
        lValue = lValue | (((long)p_bArray[4] & 0xFF) << 32);
        lValue = lValue | (((long)p_bArray[5] & 0xFF) << 40);
        lValue = lValue | (((long)p_bArray[6] & 0xFF) << 48);
        lValue = lValue | (((long)p_bArray[7] & 0xFF) << 56);
    
        double dValue = Double.longBitsToDouble(lValue);
    
        return dValue;
    }
    
    public static byte[] doubleToByteArray(double p_dValue)
    {
        byte [] bArray = new byte[8];
        long lValue;
    
        lValue = Double.doubleToLongBits(p_dValue);
    
        bArray[0] = (byte)lValue;
        bArray[1] = (byte)(lValue >> 8);
        bArray[2] = (byte)(lValue >> 16);
        bArray[3] = (byte)(lValue >> 24);
        bArray[4] = (byte)(lValue >> 32);
        bArray[5] = (byte)(lValue >> 40);
        bArray[6] = (byte)(lValue >> 48);
        bArray[7] = (byte)(lValue >> 56);
    
        return bArray;
    }
    
    public static int byteArrayToInt(byte[] p_bArray)
    {
        int nValue;
    
        nValue = ((int)p_bArray[0]) & 0x000000FF;
        nValue = nValue | (((int)p_bArray[1] & 0x000000FF) << 8);
        nValue = nValue | (((int)p_bArray[2] & 0x000000FF) << 16);
        nValue = nValue | (((int)p_bArray[3] & 0x000000FF) << 24);
    
        return nValue;
    }
    
    public static byte[] intToByteArray(int p_nValue)
    {
        byte [] bArray = new byte[4];
    
        bArray[0] = (byte)p_nValue;
        bArray[1] = (byte)(p_nValue >> 8);
        bArray[2] = (byte)(p_nValue >> 16);
        bArray[3] = (byte)(p_nValue >> 24);
    
        return bArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a project, I have to convert a binary string into (an array of)
Recently, I have to convert an java project related to rsa/des encryption into an
I have a project working fine under MSVS 2010 SP1. I'm trying to convert
I have a project in which we often use Integer.parseInt() to convert a String
I'm not familiar with Javascript, and I have to convert a Project's Javascript codes
I'm working on this project where we don't have the source code for large
I recently have convert my project from VB6 to VB.NET2008, after the convert here
I have tried to convert an SVN project to Mercurial using svnsync and then:
I have a project that I am trying to convert to OSGi. However, this
I have a Android project for SDK1.5 and now I want to convert it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.