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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:09:45+00:00 2026-06-06T12:09:45+00:00

I need to use an embedded system running Python 1.5.2+ (!!!) with very few

  • 0

I need to use an embedded system running Python 1.5.2+ (!!!) with very few modules.
And there is no “struct” module usable…
Here is the list of usable modules :

marshal
imp
_main_
_builtin_
sys
md5
binascii

Yes that’s it, no struct module…

So, I need to create a 4 bytes representation of an unsigned short integer to send to serial…

With struct :

date = day + month * 32 + (year - 2000) * 512
time = 100 * hour + minute
data = struct.pack(b'HH', date, time)

date on 2 bytes time on 2 bytes and everybody’s happy…

But without using ‘struct’ module, how can I do that?

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

    Here is a complete translation for you

    Before

    >>> import struct
    >>> day = 1; month = 2; year = 2003
    >>> hour = 4; minute = 5
    >>> date = day + month * 32 + (year - 2000) * 512
    >>> time = 100 * hour + minute
    >>> data = struct.pack(b'HH', date, time)
    >>> data
    'A\x06\x95\x01'
    >>> data.encode("hex")
    '41069501'
    

    And after

    >>> data2 = chr(date & 0xFF) + chr((date >> 8) & 0xFF) + chr(time & 0xFF) + chr((time >> 8) & 0xFF)
    >>> data2
    'A\x06\x95\x01'
    >>> data2.encode("hex")
    '41069501'
    >>>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to calculate distance between two coordinates (lon,lat) on embedded system which doesn't
I have one doubt. I need to write site on embedded system ( memory
I am writing code for a real-time program running in an embedded Linux system.
I need to know if there is any embedded DBMS (preferably in Java and
What serial communication bus would you use in a automotive embedded system if your
I'm developing the software for an embedded system, and I need to implement a
I need to run an application in an embedded system continuously. While implementing this
I need to use AES encryption in my embedded Erlang application, but OpenSSL is
Everyone use lot of List. I need to iterate over this list, so I
I need to set the timezone on a Linux system (embedded busybox distro) but

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.