getting 64 bit integer in python
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 Getting 64 Bit Integer In Python
00:27 Answer 1 Score 37
00:54 Accepted Answer Score 3
01:33 Thank you
--
Full question
https://stackoverflow.com/questions/8676...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #integer #bit
#avk47
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Lost Meadow
--
Chapters
00:00 Getting 64 Bit Integer In Python
00:27 Answer 1 Score 37
00:54 Accepted Answer Score 3
01:33 Thank you
--
Full question
https://stackoverflow.com/questions/8676...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #integer #bit
#avk47
ANSWER 1
Score 40
Python 2 has two integer types: int, which is a signed integer whose size equals your machine's word size (but is always at least 32 bits), and long, which is unlimited in size.
Python 3 has only one integer type, which is called int but is equivalent to a Python 2 long.
ACCEPTED ANSWER
Score 2
You have a couple of options using gmpy. Here is one example using gmpy:
>>> from gmpy import mpz
>>> a=mpz(7)
>>> bin(a)
'0b111'
>>> a=a.setbit(48)
>>> bin(a)
'0b1000000000000000000000000000000000000000000000111'
>>>
gmpy2 is the development version of gmpy and includes a new type called xmpz that allows more direct access to the bits.
>>> from gmpy2 import xmpz
>>> a=xmpz(7)
>>> bin(a)
'0b111'
>>> a[48]=1
>>> bin(a)
'0b1000000000000000000000000000000000000000000000111'
>>>
There are other solutions such as bitarray you might want to look at.
Disclaimer: I maintain gmpy and gmpy2.