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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:51:02+00:00 2026-06-07T05:51:02+00:00

I need to send the length of the message in the first two bytes.

  • 0

I need to send the length of the message in the first two bytes.

Calculated the message length and it came out to be 752 lets say i.e. 02F0 in hex. Now I need to figure the special symbol corresponding to this hex value.
For getting those I use

 int num1 = Integer.parseInt("F0", 16);
 char c1 = (char) num1;

to get -> ð
The first character is not visible there (due to the encoding), but I do get the right ones. Anyhow but when I concatenate those special characters to the final message string (in ASCII) then it changes from 02F0 to 023f (confirmed that by reading the final message in ultraedit hex view). Why is that happening? 3F is 63 in decimal and I see the same thing happening with the following code snippet as well->

Charset asciicharset = Charset.forName("ASCII");
Charset iso88591charset = Charset.forName("ISO-8859-1");

byte [] a = new byte[]{(byte)0x02, (byte)0xF0};

ByteBuffer inputBuffer = ByteBuffer.wrap(a);

CharBuffer data = asciicharset .decode(inputBuffer);

ByteBuffer outputBuffer = asciicharset .encode(data); --> This is where instead of 240
for F0 I get 63, in fact I tried with any value more than 63 but it always comes back to
that

byte[] outputData = outputBuffer.array();

Any help would be appreciated.
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-06-07T05:51:04+00:00Added an answer on June 7, 2026 at 5:51 am

    I suspect your problem is not happening on the line you’ve commented but the previous line, that is:

     CharBuffer data = asciicharset .decode(inputBuffer);
    

    ASCII characters are 7-bit, not 8-bit. So any value greater that 127 (0x7F in hex) is not going to be in your asciicharset, so the decode() is probably using a default replacement. (Note that 63 corresponds with the character ‘?’, which makes sense as a default replacement.)

    UPDATE: From the comment threads above and below, now that I understand a bit more about what you’re trying to do, I would suggest not using a Charset at all (as none of the standard named encodings there will work for any/all combinations of 2 bytes you might have for the length, even UTF-16 has reserved values for example). Instead, I would suggest just using a byte buffer and only trying to convert to a string after you have stripped the initial length bytes from this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need send certain attributes(say, human readable user name) from server to client after
I need to send some bytes over UDP Protocol the start squence is 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
I need to send some information on a VxWorks message queue. The information to
I'm sending messages over TCP/IP, I need to prefix message length in a char
Need to send and receive a SOAP message in the following format from a
We need send h264 from flash to Wowza and after to vlc by RTSP
I've a custom form (created with form API) that need send an uploaded file
I need to send video stream between 2 mobile devices. Bada has no support
I need to send instant messages (like forum PMs) between users with my asp.net
I need to send an HTML report with images from an application. The report

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.