如何在python中获取long的有符号整数值? [英] How to get the signed integer value of a long in python?

查看:29
本文介绍了如何在python中获取long的有符号整数值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果lv存储的是long值,而机器是32位的,代码如下:

If lv stores a long value, and the machine is 32 bits, the following code:

iv = int(lv & 0xffffffff)

结果是 long 类型的 iv,而不是机器的 int.

results an iv of type long, instead of the machine's int.

在这种情况下,我如何获得(有符号的)int 值?

How can I get the (signed) int value in this case?

推荐答案

import ctypes

number = lv & 0xFFFFFFFF

signed_number = ctypes.c_long(number).value

这篇关于如何在python中获取long的有符号整数值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆