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 4561342
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:03:39+00:00 2026-05-21T18:03:39+00:00

I have an integer and I want to convert it to hex value. I

  • 0

I have an integer and I want to convert it to hex value. I am building a message header with each byte value of this array below indicating a specific information about the message.

I want to represent the length of the message in 2 bytes len1 and len2 below.

How do I do this?

 byte[] headerMsg =new byte []  {   0x0A, 0x01, 0x00, 0x16,
                                                0x11, 0x0d, 0x0e  len1 len2};
 int lenMsg //in 2 bytes 

Thanks

  • 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-05-21T18:03:40+00:00Added an answer on May 21, 2026 at 6:03 pm
    byte[] headerMsg =new byte []  {
        0x0A, 0x01, 0x00, 0x16,
        0x11, 0x0d, 0x0e,
        0x00, 0x00 // to be filled with length bytes
    };
    
    int hlen = headerMsg.length;
    
    // I assume the bodyMsg byte array is defined elsewhere
    int lenMsg = hlen + bodyMsg.length;
    
    
    // lobyte of length - mask just one byte with 0xFF
    headerMsg[hlen - 1] = (byte) (lenMsg & 0xFF);
    
    // hibyte of length - shift to the right by one byte and then mask
    headerMsg[hlen - 2] = (byte) ((lenMsg >> 8) & 0xFF);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a byte array, I want to convert them to integer. How to
I have RGB integer value (ex:00255), i want to convert into this format 0XFF0000FF
i have two integer array, each size 95700.i want compare to two integer arrays,i
I have an integer array: a=[3,4,5,6,7]; I want to convert it to a binary
I have a hexadecimal value, 07A5953EE7592CE8871EE287F9C0A5FBC2BB43695589D95E76A4A9D37019C8 Which I want to convert to a byte
I have an integer that gets incremented I then want this in hex so
I have a double value I want to convert it to an integer value.
Say I have the classic 4-byte signed integer, and I want something like print
I have a string D, that I want to convert into the integer 4.
I have this for example: 0 10000101 00111100000000000000000 and want to convert this to

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.