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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:31:05+00:00 2026-06-08T19:31:05+00:00

I have a byte stream with 3 bytes that I have to cast into

  • 0

I have a byte stream with 3 bytes that I have to cast into an unsigned int 32. In C I would just use bzero to zero out the memory region of my integer and then copy the memory from the stream, something like

char* stream = ...;
Uint32 myInt;
bzero(myInt,4);
memcopy(myInt, stream[0], stream[3])

Question:

How would I do this in Python?

Cheers

  • 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-08T19:31:07+00:00Added an answer on June 8, 2026 at 7:31 pm

    Even in C you should not use memcpy for binary de-serialization, because it doesn’t deal with binary representation, i.e. endianess, sign and the like. Explicitly decode binary values from a fixed representation in the stream to the platform’s native representation.

    In Python, you’d read the bytes from the stream, pad them according to the endianess, and then unpack them with struct:

    chunk = fileobj.read(3)
    # decode bytes as little-endian, signed integer
    chunk += '\x00'
    number = struct.unpack('<i', chunk)
    

    fileobj is a file-like object, representing the opened stream, i.e. a file opened with open(filename, 'rb').

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

Sidebar

Related Questions

I have a byte stream that may be UTF-8 data or it may be
I have an API call that returns a byte array. I currently stream the
I have a stream of bytes that is being read in from a socket
I have client-server app. Client on C++, server on Java. I am sending byte-stream
I have a byte array which needs to be marshalled into the following struct:
I have a byte[] that i obtained using Object ArrayList<Obj> Can anyone tell me
I have a byte array highlighted below, how do I insert it into a
I have a list of bytes that represent raw samples read in from an
I have a stream of bytes (given by a BufferedInputStream) which represents a sequence
I probably should have just put all this in one question, sorry for that

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.