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

  • Home
  • SEARCH
  • 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 6528353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:31:36+00:00 2026-05-25T09:31:36+00:00

How do you produce a 16 bit unsigned integer and a 64-bit unsigned integer

  • 0

How do you produce a 16 bit unsigned integer and a 64-bit unsigned integer in Java? This question is related to implementing a standard. I am not in a position to change the spec.

Other perhaps relevant bits of the spec. this question is related to:

  • most significant bit MUST be 0.
  • must be expressed in network byte order.

Application context: The number (in either form) represents the length of data being sent. The length can be big or small. I’ve first found the length of the message to be sent as a long.

So I’m starting with: long length = getLength();

I then need to convert the long variable “length” to either of the two above, depending on how big it is. In the end, I’m pretty sure I’ll need to do a .getBytes() when I send the length. The recipient will interpret as described above.

  • 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-25T09:31:36+00:00Added an answer on May 25, 2026 at 9:31 am

    If the most significant bit must be zero, then the number is the same whether it is signed or unsigned (assuming a two’s complement representation). So for instance, 16 bit integers with the MSB zero represent the numbers from 0 to 32767 inclusive.

    Assuming that you are writing to an OutputStream and that your definition of “network order” is most significant byte first, then you need to do something like this:

    public void writeShort(OutputStream os, short s) throws IOException {
        os.write((byte) (s >> 8));
        os.write((byte) s);
    }
    

    and

    public void writeLong(OutputStream os, long l) throws IOException {
        os.write((byte) (l >> 56));
        os.write((byte) (l >> 48));
        os.write((byte) (l >> 40));
        os.write((byte) (l >> 32));
        os.write((byte) (l >> 24));
        os.write((byte) (l >> 16));
        os.write((byte) (l >> 8));
        os.write((byte) l);
    }
    

    Note that these works for signed and unsigned integers. (Or to be more precise for the Java context, they work if the argument represents a signed or unsigned integer.)

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

Sidebar

Related Questions

This bit of code does not produce any errors: //if the image has tags
I am looking for a hashing algorithm that produces a 31/32 bit signed/unsigned integer
I need to convert Java long datatype (64-bit) data into legacy c++ app unsigned
I'm trying to produce a report that has multiple grouping but does not just
I'm writing a program right now which produces four unsigned 32-bit integers as output
This is a further discussion on this question: Why is it still possible to
This might be a silly question, but here goes : I hashed a dictionary
I'm using a bit of jquery to search Flickr, produce a set of thumbnails,
So if I wanted to produce a bit of code to convert an flv
I'm using 64 bit matlab r2010a on windows 7 (this may be relevant if

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.