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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:12:55+00:00 2026-05-28T01:12:55+00:00

I have a message static int[] message = { 0x01, 0x10, 0x00, 0x01, //

  • 0

I have a message

static int[] message = {
        0x01, 0x10, 0x00,
        0x01, // port addres 01 - 08
        0x00, 0x01, 0x02,
        0x06, 0x00,
        0xA4, 0x21
};

I know the data are right, as of I’m writing them to COM port with RXTX, and I got right HW reaction

I know that 0x01 is 1 value, and sent really like 01 (which is two bits, quarter byte long)

When I need to adjust the message, is generating values like this right?

message[index] = 1 & 0xff

I see the output of this snippet, and it looks properly

for (int i = 0; i < 255; i++) {
    System.out.println(i & 0xff);
}

Is there any sheet you’d recommend me to read?
Is storing these numbers in int right, as we cannot use byte (-128, +127) for values up to <0x00, 0xFF> range

  • 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-28T01:12:55+00:00Added an answer on May 28, 2026 at 1:12 am

    You probably want to use a ByteBuffer for what you need, and wrap it under a class.

    I don’t know your exact message format, but let’s say for a moment this is 3 bytes of data and 1 byte of a port:

    public final class Message
    {
        private static final MESSAGE_SIZE = 4;
        private static final PORT_OFFSET=3;
    
        private final ByteBuffer buf;
    
        public Message()
        {
            buf = ByteBuffer.allocate(MESSAGE_SIZE);
        }
    
        public void setPort(final byte b)
        {
            buf.put(PORT_OFFSET, b);
        }
    
        // etc
    
        public byte[] getRaw()
        {
            return buf.array();
        }
    }
    

    You can even use ByteBuffer’s hashCode() and equals() to compare messages, if you only ever use absolute get/put methods (otherwise quite a bit of gymnastic is in order).

    I used this technique to read/write NRPE packets.

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

Sidebar

Related Questions

I have a web service , i add some extra class which have message
I have a message handler, which consumes from a JMS queue and that sends
I have 2 Message driven beans. 2 Activation Specs for these beans. I have
I have a message box with 3 buttons: Yes, No, Help: var result =
I have a message that I want to fadeIn when a form is successfully
I have a Message table and a User table. Both are in separate databases.
In C++, a console application can have a message handler in its WinMain procedure,
I have a simple message box in a WPF application that is launched as
I have a status message box (div box) positioned at the bottom of a
I have this error message: Msg 8134, Level 16, State 1, Line 1 Divide

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.