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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:08:38+00:00 2026-05-13T23:08:38+00:00

I have a header field of 2 bytes where first four bits are packet

  • 0

I have a header field of 2 bytes where first four bits are packet type and other 12 bits are for length. but i don’t know how to store this values and retrieve them.

I am using ms c++ for client and java for server. It is the client which has to set this values and server has to retrieve it.

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-13T23:08:38+00:00Added an answer on May 13, 2026 at 11:08 pm

    Storing

    unsigned short get_header(unsigned char type, unsigned short length)
    {
      return (static_cast<unsigned short>(type) << 12) | length;    
    }
    

    Retrieving (from unsigned short)

    unsigned short header = /* get 2 header bytes */
    unsigned char type = header >> 12;
    unsigned short length = header & 0xFFF;
    

    Retrieving (from unsigned char[2])

    unsigned char bytes[2] = /* get 2 header bytes */
    unsigned char type = bytes[0] >> 4;
    unsigned short length = bytes[0] & 0xF | bytes[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Why does C++ have header files and .cpp files?
Based on the response to this question: Why does C++ have header files and
I have a header <h1>My Header</h1> It has a height of 150px and a
Lets say I have a header banner on a webpage I'm about to print.
Lets say that I have a header user control in a master page, and
I am having trouble with IE7. I have a header, which is an IMG.
I have a c++ header file containing a class. I want to use this
I am trying to have a table header, in a seperate div stay in
I have a couple of header files, which boil down to: tree.h: #include element.h
I have to include many header files, which are in different sub-directories. Is there

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.