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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:12:37+00:00 2026-05-28T20:12:37+00:00

I am using this nice little package construct for binary data parsing. However, I

  • 0

I am using this nice little package “construct” for binary data parsing. However, I ran into a case where the format is defined as:

31     24 23              0
+-------------------------+
| status |  an int number |
+-------------------------+

Basically, the higher 8 bits are used for status, and 3 bytes left for integer: an int type with higher bits masked off. I am a bit lost on what is the proper way of defining the format:

  • The brute force way is to define it as ULInt32 and do bit masking myself
  • Is there anyway I can use BitStruct to save the trouble?

Edit

Assuming Little Endian and based on jterrace’s example and swapped=True suggestion, I think this is what will work in my case:

sample = "\xff\x01\x01\x01"
c = BitStruct("foo", BitField("i", 24, swapped=True), BitField("status", 8))
c.parse(sample)
Container({'i': 66047, 'status': 1})

Thanks

Oliver

  • 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-28T20:12:38+00:00Added an answer on May 28, 2026 at 8:12 pm

    This would be easy if construct contained Int24 types, but it doesn’t. Instead, you can specify the bit lengths yourself like this:

    >>> from construct import BitStruct, BitField
    >>> sample = "\xff\x01\x01\x01"
    >>> c = BitStruct("foo", BitField("status", 8), BitField("i", 24))
    >>> c.parse(sample)
    Container({'status': 255, 'i': 65793})
    

    Note: The value \x01\x01\x01 is 65536 + 256 + 1 = 65793

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

Sidebar

Related Questions

So I rewrote my paths to something like: URL/really/nice/paths/ using mod_rewrite rules like this:
Using iOS and a UISearchBar you can have a nice little cancel button setup
I have wrote this little script which generates a nice random password. The problem
This .aspx page has a very nice set of collapsible sections with little +
Hey, I've got this nice little piece of code, much like all the other
This is going to be a nice little brainbender I think. It is a
I'm using Github, and realized they have a nice little api for accessing repo
I just started using Instruments, a nice little tool for testing memory allocations/ leaks
After using Meebo I noticed that they had a nice little system for continually
http://code.google.com/appengine/articles/update_schema.html Trying to work this out for a nice little updater across my web

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.