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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:51:27+00:00 2026-06-04T11:51:27+00:00

Pointers are not common in Python, neither the var declaration type. I’m triyng to

  • 0

Pointers are not common in Python, neither the var declaration type. I’m triyng to do this in Python.

C++:

 ...a function
 flt32 f;
 int32 sign, exp, man, *tms;
 tms = (int *) &f;
 ...(operations)
 *tms = sign | exp | man;
 return (f);

as you can see, tms points to f data, but just the int part of the float (btw, this function works perfectly).

With ctypes I can use pointers in Python:

from ctypes import * 
f = c_float(12.3)
tms = pointer(f) # tms should be: tms = c_int32(value)
print tms.contents.value #12.3000001907

The problem here is that tms becomes instantly the type of f, so both variables are float (tms should be tms = c_int32(a_value)).
It is possible to use a pointer that just matches the int value from a float variable in Python?

  • 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-04T11:51:29+00:00Added an answer on June 4, 2026 at 11:51 am

    If you really want to do this in Python, you can use ctypes.cast() to cast a float pointer to int pointer, or you can use struct to pack the float value in to a string and unpack it to int. Here is an example:

    I use ctypes.cast() to view float value memory as int, and use struct to convert it back:

    In [5]: from ctypes import *
    In [6]: f = c_float(12.3)
    In [8]: tmp = cast(pointer(f), POINTER(c_int)) 
    In [9]: tmp.contents
    Out[9]: c_long(1095027917)
    In [10]: tmp.contents.value
    Out[10]: 1095027917
    In [11]: hex(tmp.contents.value)
    Out[11]: '0x4144cccd'
    
    In [13]: import struct
    In [16]: struct.unpack("f",struct.pack("I", 1095027917))
    Out[16]: (12.300000190734863,)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any reasons why this can not be standard behavior of free() ? multiple pointers
I would like to pass some (dll or not) function pointers as arguments to
I want to create an array to store actual objects and not pointers to
I do not understand pointers. Where can I learn more about them?
Do smart pointers handle down casting, and if not what is a safe way
I'm really not sure what it is (if it's an array of pointers, or
Does anyone have any pointers to good resources concerning mesh networks? Maybe I'm not
Hi I have some experience with programming but I'm not very good with pointers.
AFAIK, for pointers/references static_cast, if a class definition is not visible to compiler at
Is it possible to call a c(++) static function pointer (not a delegate) like

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.