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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:10:46+00:00 2026-06-18T12:10:46+00:00

I have this strange problem with using find()/index() (don’t know if there is any

  • 0

I have this strange problem with using find()/index() (don’t know if there is any difference between them) with bytesarray.

I’m working with binary file, I have loaded it as bytesarray and now I need to find tokens that indicate beginning of message and end of message.
Everything works fine with finding the beginning of message (0x03 0x02) but I keep getting the same position where I started searching when I search for the end (0x00)

    msg_start_token = bytearray((int(0x03), int(0x02)))
    msg_end_token = bytes(int(0x00))

    def get_message(file,start_pos):
        msg_start = file.find(msg_start_token,start_pos) + 2
        print(hex(msg_start))
        msg_end = file.find(msg_end_token,msg_start)
        print(hex(msg_end))
        msg = file[msg_start:msg_end]
        print(msg)
        return (msg, msg_end)  

I haven’t really worked with binary files before so I don’t know maybe I’m missing something really simple in fact.

  • 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-18T12:10:47+00:00Added an answer on June 18, 2026 at 12:10 pm

    You need to start searching at the next position, so search at:

    file.find(msg_start_token, start_pos + 1)
    

    because the search starts at start_pos, and if msg_start_token is found at that position, find will return start_pos of course.

    As for the difference between .index() and .find(); .index() raises a ValueError exception if the substring is not found, while .find() returns -1 instead.

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

Sidebar

Related Questions

I have a strange problem. I do this query in a node.js server using
I've got this strange problem using py-amqp and the Flopsy module. I have written
I have this strange problem about loading images using AsyncTask in ListView.In my ListView,
I have this strange problem. I am retrieving twitters and it works on the
i have this strange problem with the PHP function CTYPE_ALNUM if i do: PHP:
Starting from Android 3.2 I have this strange problem. It's very easy to reproduce:
I have a strange problem. I have this method, which should generate a Date
I am facing a strange problem and have no idea how to fix this
I have a problem with a strange crash on iPad 5.0. This crash only
Right, this is a strange problem I have been toying with for a while

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.