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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:36:44+00:00 2026-05-27T00:36:44+00:00

I read byte[] from socket as Param_Code . there is a condition for Param_Code

  • 0

I read byte[] from socket as Param_Code. there is a condition for Param_Code as below:

• Option 1: Sometimes the Param_Code corresponds to the ID

• Option 2: Sometimes the Param_Code corresponds to 0x40000000 + the ID

• Option 3: Sometimes the Param_Code corresponds to 0x80000000 + the ID

This is my code:

byte[] cbuf = new byte[4];

socketReader.read(cbuf, 0, 4);

int Param_Code = byteArrayToIntBI(cbuf, 0);

public static int byteArrayToIntBI(byte[] b, int offset) {
    int value = 0;
    for (int i = 3; i > -1; i--) {
        int shift = (i) * 8;
        value += (b[i + offset] & 0x000000FF) << shift;
    }
    return value;
}

My question is, How can i know (with if statement or something else) when the Param_Code is one of above option?

How can i get ID?

if( ? ){
        it is Option 1 and ID = ?
}else if( ? ){
        it is Option 1 and ID = ?
}else if( ? ){
        it is Option 1 and ID = ?
}
  • 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-27T00:36:45+00:00Added an answer on May 27, 2026 at 12:36 am

    You should add some restriction on ID. Because we cannot apply mask in that case.

    Imagine, that you got 0x81234123. It can be:

    • ID 0x81234123
    • ID 0x41234123
    • ID 0x01234123

    Provide additional condition to avoid that ambiguity.
    i can only assume that your ID doesn’t include first hexadecimal number so, in that case use mask: ID = NUM & 0x0FFFFFFF

    NUM is actually your byte[4]

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

Sidebar

Related Questions

I read byte[] from socket as Param_Code which includes ID. byte[] cbuf = new
I need to read data from socket byte by byte. I try to do
I use this code for reading from socket : int n ; char buffer[256];
I read in a Byte Array generated from a function called from an external
I have a byte array in memory, read from a file. I would like
I'm using System.IO.Stream.Read(byte[] buffer, int offset, int count) . Is there an alternative to
I am trying to read a Network Stream from a socket. I know that
I have a stream of bytes that is being read in from a socket
I'm trying to use qFromBigEndian to read a 32-bit int from a byte stream
I am writing a byte array from a socket client as: byte[] arr =

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.