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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:46:40+00:00 2026-05-10T22:46:40+00:00

I need to convert strings in Python to other types such as unsigned and

  • 0

I need to convert strings in Python to other types such as unsigned and signed 8, 16, 32, and 64 bit ints, doubles, floats, and strings.

How can I do this?

  • 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. 2026-05-10T22:46:41+00:00Added an answer on May 10, 2026 at 10:46 pm

    You can convert a string to a 32-bit signed integer with the int function:

    string = "1234" i = int(string)  # i is a 32-bit integer 

    If the string does not represent an integer, you’ll get a ValueError exception. Note, however, that if the string does represent an integer, but that integer does not fit into a 32-bit signed int, then you’ll actually get an object of type long instead.

    You can then convert it to other widths and signednesses with some simple math:

    s8 = (i + 2**7) % 2**8 - 2**7      # convert to signed 8-bit u8 = i % 2**8                      # convert to unsigned 8-bit s16 = (i + 2**15) % 2**16 - 2**15  # convert to signed 16-bit u16 = i % 2**16                    # convert to unsigned 16-bit s32 = (i + 2**31) % 2**32 - 2**31  # convert to signed 32-bit u32 = i % 2**32                    # convert to unsigned 32-bit s64 = (i + 2**63) % 2**64 - 2**63  # convert to signed 64-bit u64 = i % 2**64                    # convert to unsigned 64-bit 

    You can convert strings to floating point with the float function:

    f = float("3.14159") 

    Python floats are what other languages refer to as double, i.e. they are 64-bits. There are no 32-bit floats in Python.

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

Sidebar

Ask A Question

Stats

  • Questions 91k
  • Answers 91k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In PowerShell: Use the -recurse switch and pipe to foreach.… May 11, 2026 at 6:21 pm
  • Editorial Team
    Editorial Team added an answer Yes In your web.config <sessionState mode="InProc" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnectionString="data source=127.0.0.1;Trusted_Connection=yes" cookieless="false"… May 11, 2026 at 6:21 pm
  • Editorial Team
    Editorial Team added an answer If you don't need to sort in-place, you could use… May 11, 2026 at 6:21 pm

Related Questions

I need to convert unicode strings in Python to other types such as unsigned
I need to convert between python objects and c strings of various encodings. Going
I'm new to python, and have a list of longs which I want to
I'm not exactly sure how to ask this question really, and I'm no where

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.