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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:22:15+00:00 2026-05-22T14:22:15+00:00

How can I match a byte array to a larger byte array and get

  • 0

How can I match a byte array to a larger byte array and get the unique data and the location in the byte array that the pattern ends?


FF FF FF FF XX XX XX XX FF FF FF FF (any length of any bytes goes here) 2E XX XX XX 00


I have the above pattern (where XX is any byte) and i need to get bolded parts plus the location in the array of the last byte, How can I do this? (note: I need to get all occurrences of this pattern)

I cannot convert it to a string as it has null bytes (0x00) and they are often part of the first four XX XX XX XX bytes.

I’ve been trying to figure this out for a while now and would appreciate it if you guys could help me out! Thanks.

Edit: the above bytes are in hex

  • 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-22T14:22:16+00:00Added an answer on May 22, 2026 at 2:22 pm

    Who says you can’t convert it to a string?

    byte[] bytes = new byte[]
    {
        0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x31, 0x32, 0x33, 0x34, 0xff, 0x2a, 0x00
    };
    var s = Encoding.Default.GetString(bytes);
    Console.WriteLine(bytes.Length);
    Console.WriteLine(s.Length);
    foreach (var c in s)
    {
        Console.Write("0x{0:X2}, ", (int)c);
    }
    Console.WriteLine();
    

    Both the array and the string are shown with a length of 13. And the bytes output from the string are the same as the bytes in the array.

    You can convert it to a string. Then you can use regular expressions to find what you’re looking for.

    Note that Encoding.Default might not be what you’re looking for. You want an 8-bit encoding that doesn’t modify any of the characters.

    But if you want an algorithmic way to do it, there are a couple of ways that spring to mind. First way (and probably easiest) is to scan forward looking for 2E followed by three bytes, and then a 00. Then start at the beginning again and see if you find FF FF FF FF XX XX XX XX FF FF FF FF. That’s not the fastest way to do things, but it’s pretty easy.

    Note that if you search backwards from the 2E, you could end up "finding" a shorter string. That is, if your input was:

    FF FF FF FF XX XX XX XX FF FF FF FF 01 02 FF FF FF FF XX XX XX XX FF FF FF FF 0A 0B 2E XX XX XX 00

    There are two occurrences of the starting pattern. If you searched backwards from the 2E, you’d match the second one, which probably isn’t what you want.

    The other way is to build yourself a little state machine that searches forward. That’ll be faster, but a bit more difficult.

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

Sidebar

Related Questions

How can I match a pattern in regex that can contain anything (letters,numbers,...) but
I've been writing a program that can determine any and every data about an
I have an array of RGB values, whose size I can guarantee to match
I have to send the audio data in byte array obtain by recording from
I'm trying to implement a filecopy method that can match the performance a copy
Overview: I have an array of 20 byte strings that needs to be stored
Quick & dirty Q: Can I safely assume that a byte of a UTF-8,
How can I build a regular expression in python which can match all the
How can I match (PCRE) everything inbetween two tags? I tried something like this:
How can you match the following words by PHP, either by regex/globbing/...? Examples INNO,

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.