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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:45:24+00:00 2026-06-15T08:45:24+00:00

I have hypothetical data coming from a UDP connection that is in binary form.

  • 0

I have hypothetical data coming from a UDP connection that is in binary form.

Its composed of 5 fields, with a size of 25 bits

their offsets as follows

 1. 0-4 ID
 2. 5-10 payload
 3. 11-12 status
 4. 13-23 location
 5. 23-25 checksum

How do I read in this data?

        DatagramSocket serverSocket = new DatagramSocket(18000);
        byte[] receiveData = new byte[1024];

        while (true)
        {
            DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
            serverSocket.receive(receivePacket);

           //not sure how I should be reading the raw binary data back in

        }

How would I store off this data?

  • 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-15T08:45:25+00:00Added an answer on June 15, 2026 at 8:45 am

    DatagramPacket’s getData returns the payload as a byte[]. You can use Arrays.copyOfRange to get the individual fields (I’m assuming you meant bytes in your question, not bits):

    while (true) {
        DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
        serverSocket.receive(receivePacket);
        // get the entire content
        byte telegramContent[] = receivePacket.getData();
        // and slice it up:
    
        byte ID[] = Arrays.copyOfRange(telegramContent,0,5); 
        byte payload[] = Arrays.copyOfRange(telegramContent,6,11);
        // and so on.
    }
    

    After this step you’ll have your fields as individual byte arrays, probably some postprocessing/reassembly into other types will be necessary. During this step probably the most annoying thing is that all Java’s types are signed whereas in many communication protocols unsigned entities are used, so be careful during this step.

    Not mentioned in your question but you might need it later on: assembly of messages for transmission. I like to use GNU Trove’s TByteArrayList for that task as you don’t need to worry about reserving a byte[] with the correct length before you start, just copy in bytes or message segements and once you’re done call toArray and voilà, your byte[] is ready for transmission.

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

Sidebar

Related Questions

I have a hypothetical tree view that contains this data: RootNode Leaf vein SecondRoot
I have a hypothetical set of data with 3 columns that has monthly profit
I have data composed of a list of employers and a list of workers
I have a tree data structure that is L levels deep each node has
I have a partial view that sometimes needs to collect data and sometimes just
Hypothetical example: I have an SQL table that contains a billion or so transactions:
I have a hypothetical situation of sending data units, each of a thousand bytes.
I have to believe there's a way to clear image data from memory once
I have data in my database that looks like this: Date (DateTime) Type (varchar)
Let's say I have a list and am streaming data from a namedpipe to

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.