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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:26:22+00:00 2026-06-06T10:26:22+00:00

So generally I’m using Netty and it’s BigEndianHeapChannelBuffer to receive unsinged short (from c++

  • 0

So generally I’m using Netty and it’s BigEndianHeapChannelBuffer to receive unsinged short (from c++ software) in Java.
When I do it like this:

buf.readUnsignedByte(); buf.readUnsignedByte();

it returns:
149 and 00. Till now everything is fine. Because server sent 149 as unsigned short [2 bytes].

Instead of this I would like to receive unsigned short (ofc after restarting my application):

buf.readUnsignedShort();

and magic happens. It returns: 38144.

Next step is to retrieve unsigned byte:
short type = buf.readUnsignedByte();
System.out.println(type);

and it returns: 1 which is correct output.

Could anyone help me with this?
I looked deeper and this is what netty does with it:

public short readShort() {
    checkReadableBytes(2);
    short v = getShort(readerIndex);
    readerIndex += 2;
    return v;
}

public int readUnsignedShort() {
    return readShort() & 0xFFFF;
}

But still I can’t figure what is wrong. I would like just be able to read that 149.

  • 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-06T10:26:24+00:00Added an answer on June 6, 2026 at 10:26 am

    The answer is to change endianness. Thanks to Roger who in comments wrote:

    Not much magic, 149*256+0=38144. You have specified BigEndian so this seems correct, the most significant byte is sent first

    and:

    @mickula The short is two bytes, where one of the bytes is “worth” 256 times as much as the other, Since you use BigEndian the first byte is the one “worth” more. Similar to the decimal number 123 of the digits 1, 2, and 3. The first position is with 10 times the next position which is worth 10 times the next, and so on. So 1 * 100 + 2 * 10 + 3 = 123 when the digits are transferred one at a time. If you see 1, 2, and 3 as little endian you would use 1 + 2 * 10 + 3 * 100 = 321. The 256 is because the size of a byte is 256. –

    Thanks to his comments I just switched endianess in server bootstrap by adding:
    bootstrap.setOption("child.bufferFactory", new
    HeapChannelBufferFactory(ByteOrder.LITTLE_ENDIAN));

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

Sidebar

Related Questions

Generally this question comes from Eclipse suggesting to add a serial version UID on
Generally, message boxes work like this: if(ShowMessageBox(Title,Text,MB_YES_NO) == MB_YES) { //the user responded yes
I generally do something like this, but if feels nasty and not very dry:
generally by using my-eclipse we add struts,hibernate and jpa capabilities to our applications/projects, like
Generally we import a tlb file at the starting of the program like #include
Generally speaking, what are your recommendations on this? Currently takes close to 10 minutes
Generally I seem to be able to fix IE problems nowadays.. but this one
Generally don't do OO-programming in Python. This project requires it and am running into
Generally we are using interface concept for RMI implementation also in Event listening ,we
Generally for updating an item i am using public static void UpdateCustomer<T>(T item) where

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.