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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:55:57+00:00 2026-05-18T22:55:57+00:00

Using the struct module in python 2.4.3 why is there a difference between calcsize(!BHB)

  • 0

Using the struct module in python 2.4.3 why is there a difference between calcsize(“!BHB”) and calcsize(“BHB”)?
whereby;
when

from struct import *
calcsize("!BHB") == 4
calcsize("BHB") == 5

I understand the big endian and little endian concept, but don’t really get it in terms of bytes placement for the above formats.

  • 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-18T22:55:58+00:00Added an answer on May 18, 2026 at 10:55 pm

    The reason for that is explained in the Python Docs and it is due to padding issue when you are using a mixed structure members (BHB)

    1. Padding is only automatically added between successive structure members.
      No padding is added at the beginning or the end of the encoded struct.

    2. No padding is added when using non-native size and alignment,
      e.g. with ‘<’, ‘>’, ‘=’, and ‘!’.

    See this:

    >>> struct.pack("BHB",1,1,1)
    '\x01\x00\x01\x00\x01'
    >>> struct.pack("=BHB",1,1,1)
    '\x01\x01\x00\x01'
    

    In the first case, the padding was added to Byte because it was using the default native size and alignment and you explicitly set it standard size using ‘=’, no padding was done.

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

Sidebar

Related Questions

I'm accessing a C struct which contains some time_t fields using python ctypes module.
I am using python struct module to create custom binary files. The file itself
When using the python struct module on can specify a format string that declares
After getting a struct from C# to C++ using C++/CLI: public value struct SampleObject
I compress my files using this script import pylzma, struct i = open(path+fileName,'rb') o
I am creating a python module that is implemented in C++. I am using
I want to parse an integer that is unpack() ed using the struct module
I'm trying to pass a C struct from C++ into python as a numpy
I'm using Boost.Python to create Python modules from C++ classes. And I ran into
I'm trying to extract text from a large number of PDFs using PDFMiner python

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.