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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:37:33+00:00 2026-05-30T19:37:33+00:00

Every time i come across the value -15 i want to put it in

  • 0

Every time i come across the value “-15” i want to put it in a new byte array… how would i do this? I think i’m just tired and getting way to confused and worked up… please help… code is as follows:

    fileContent = "S107184CB78120EA52S107184CB78120EA57"; 
    int len = fileContent.length(); 
    byte[] data = new byte[len/2]; 
    for (int i = 0; i < len; i += 2) 
    {
        data[i / 2] = (byte) ((Character.digit(fileContent.charAt(i), 16) << 4) + Character.digit(fileContent.charAt(i+1), 16));
    }

this will give me the following: [-15, 7, 24, 76, -73, -127, 32, -22, 82, -15, 7, 24, 76, -73, -127, 32, -22, 87]

what i want from here is to have every element from -15 up until the next -15 (but not including it) in a separate byte array. i want to do that every time i come across another -15.. how would i do this?

  • 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-30T19:37:34+00:00Added an answer on May 30, 2026 at 7:37 pm

    Assuming -15‘s occur randomly, you need a dynamic array, which in java is a List.
    Once you’ve collected up all your elements, you can convert the List to an array easily enough.

    It would look something like this:

    String fileContent = "S107184CB78120EA52S107184CB78120EA57";
    int len = fileContent.length();
    List<Byte[]> arrays = new ArrayList<Byte[]>();
    List<Byte> data = new ArrayList<Byte>();
    for (int i = 0; i < len; i += 2) {
        byte b = (byte) ((Character.digit(fileContent.charAt(i), 16) << 4) + Character.digit(fileContent.charAt(i + 1), 16));
        if (b == -15) {
            arrays.add(data.toArray(new Byte[data.size()]));
            data.clear();
        }
        data.add(b);
    }
    arrays.add(data.toArray(new Byte[data.size()]));
    

    Note that this creates a List<Byte[]>, not a List<byte[]>. I chose this because I could use the .toArray() method of List. If you want a List<byte[]>, you’ll need to manually literate over data in the if block.

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

Sidebar

Related Questions

In every webapp I build, I come across this issue. I want to set
This questions always stumps me for a couple of seconds every time I come
I'm somewhat new to rails and every time I think I'm getting it I
I've come across a website which changes it's field names every time it is
Every day I always come across this dilemma - is it best practice to
Every time I download SQLite, I come across the fact that they provide several
Every time I come back the data to the user, I see that .NET
Every time I run the code below it is supposed to come up with
Every time i make a new JFrame object, the frame appears in the 0,0
Every time I try to access my localhost/phpmyadmin it gives me this error --->

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.