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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:18:35+00:00 2026-06-07T01:18:35+00:00

I need to prepend the string 00 or byte 0x00 to the beginning of

  • 0

I need to prepend the string “00” or byte 0x00 to the beginning of a byte array? I tried to do it with a for loop but when I convert it to hex it doesn’t show up in the front.

  • 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-07T01:18:38+00:00Added an answer on June 7, 2026 at 1:18 am

    The string “00” is different than the number 0x00 when converted to Bytes. What is the data type you are trying to prepend to your byte array? Assuming it’s a Byte representation of the string “00”, try the following:

    bytes[] orig = <your byte array>;  
    String prepend = "00";  
    bytes[] prependBytes = prepend.getBytes();  
    bytes[] output = new Bytes[prependBytes.length + orig.length];
    
    for(i=0;i<prependBytes.length;i++){
        output[i] = prependBytes[i];
    }
    
    for(i=prependBytes.length;i<(orig.length+prepend.lenth);i++){
      output[i] = orig[i];
    }
    

    or you can use Arrays.copy(…) instead of the two for loops as mentioned before to do the prepending. See How to combine two byte arrays

    Alternativly, if you are trying to literally prepend 0 to your byte array, decalare prependBytes in the following way and use the same algorithm

    byte[] prependBytes = new byte[]{0,0};
    

    Also you say that you’re converting your byte array to hex, and that may truncate leading zeros. To test this, try prepending the follwoing and converting to hex and see if there is a different output:

    byte[] prependBytes = new byte[]{1,1};
    

    If it is removing the leading zeros that you want, you may wish to convert your hex number to a string and format it.

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

Sidebar

Related Questions

I am creating XML using a while loop, but now I need to prepend
I need to prepend a single value to an IEnumerable (in this case, IEnumerable<string[]>
Need a list of Pcap.Net members or classes? Their website doesn't have much documentation
This should be simple. I have ajax returning string, with multiple divs. I need
I have a string array lines, for example lines = [| hello; world |]
I need to prepend a huge DIV block, which can be seen at the
In my makefile I have an object variable. I need to prepend obj/ to
I need to take a string that was originally read in from a text
I'm trying to prepend a string a read-only, multi-line TextBox using the following code:
I'm trying to prepend require_once 'bootstrap.php'; string to each schema.yml file in specific dirrectory.

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.