473,569 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bits module -- early working version

I've been working on a module to get at the bits of all numeric types
(no, I haven't thought of how to solve the decimal data type that is
coming). I've finally got the bits module to pass all of my own tests,
so I'm looking for bug reports, design critiques, and general input. I
eventually plan to release this under an MIT-style license. If you are
interested in seeing read access to the bits of python's numbers, and
want to see what I'm up to / critique someone else's work / volunteer to
help extend, check out:

http://members.dsl-only.net/~daniels/bits.html

If you want to know what questions I have, here are my current set:

1) Do you know a case that fails?
2) Should the names be lsb, lsbit, or lsbitno (and similarly for msb*)?
I've gone with lsb, but cases can be made for the others.
3) Is "extract" the right name, or should I us a name more like "bits"?
4) Should bit(v, N) somehow be subsumed in extract(v, l, hi) (or
whatever extract should be called)?
5) Have I adequately explained what these functions do?
6) Do these functions work as-is (from source) for various machines?
I know/believe Intel x86/pentia work; what about alpha, 68K, ....
7) Should bitcount simply raise and exception on negative input?
8) If you supply an unexpected argument type for the number, should I
try to calla corresponding method? (__bit__ for bit, __msb__ for
msb, ....)

So I'd like feedback before actually releasing.

--
-Scott David Daniels
Sc***********@A cm.Org
Jul 18 '05 #1
1 1592
>Subject: Bits module -- early working version
From: Scott David Daniels Sc***********@A cm.Org
Date: 2/12/2004 11:55 PM Central Standard Time
Message-id: <40******@nntp0 .pdx.net>

I've been working on a module to get at the bits of all numeric types
(no, I haven't thought of how to solve the decimal data type that is
coming). I've finally got the bits module to pass all of my own tests,
so I'm looking for bug reports, design critiques, and general input. I
eventually plan to release this under an MIT-style license. If you are
interested in seeing read access to the bits of python's numbers, and
want to see what I'm up to / critique someone else's work / volunteer to
help extend, check out:

http://members.dsl-only.net/~daniels/bits.html

If you want to know what questions I have, here are my current set:

1) Do you know a case that fails?
2) Should the names be lsb, lsbit, or lsbitno (and similarly for msb*)?
I've gone with lsb, but cases can be made for the others.
3) Is "extract" the right name, or should I us a name more like "bits"?
4) Should bit(v, N) somehow be subsumed in extract(v, l, hi) (or
whatever extract should be called)?
5) Have I adequately explained what these functions do?
6) Do these functions work as-is (from source) for various machines?
I know/believe Intel x86/pentia work; what about alpha, 68K, ....
7) Should bitcount simply raise and exception on negative input?
8) If you supply an unexpected argument type for the number, should I
try to calla corresponding method? (__bit__ for bit, __msb__ for
msb, ....)

So I'd like feedback before actually releasing.
Testing for the lsb allows me to speed up my Collatz program since I can
extract all the factors of 2 in one fell swoop as opposed to iterating through
each one. For the large numbers I work with (2**100000 - 1 in the following
example), this optimization is signifigant:

c:\python23\use r>python collatz_.py 100000

standard Python long ints without optimization
r1 863323 r2 481603 in 632.234999895 seconds

optimized with bits.lsb() bit scanning
r1 863323 r2 481603 in 332.5 seconds

But I had already been using the gmpy module which has the scan1()
function that does the same thing as bits.lsb(). And gmpy long ints are
more efficient than the Python long ints. Together, I get much better
performance:

optimized with gmpy.scan1() bit scanning
r1 863323 r2 481603 in 131.733999968 seconds

For my work, I can't see any advantage in using bits over gmpy.

--
-Scott David Daniels
Sc***********@ Acm.Org


--
Mensanator
Ace of Clubs
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17644
by: x-herbert | last post by:
Hi, I have a small test to "compile" al litle script as a WMI-Tester. The script include a wmi-wrapper and "insert" the Win32-modeles. here the code: my "WMI-Tester.py" ----- import wmi
2
1640
by: Sandeep Gupta | last post by:
I've compiled Python 2.3.3 on NetBSD and the thread (and therefore the threading) module is not available. Am I missing the module because of the way I made the binary? I could use the dummy_threading module, but then I'm sure I'd run into deadlocks. Thanks
3
4559
by: Geoffrey | last post by:
I am working on a file conversion project that reads data from a one file format, reformats in and writes in out to another. The data is records of informations - names address, account number,statistics. The numeric values in the original file are stored in what appears to be a "packed" data format,using a structure that does not use any...
13
1599
by: bobueland | last post by:
I'm a newbie experimenting with Python. I want to incrementally develop a module called 'circle'. The problem is now that the file name is used for two purposes. To keep track of the version number and as the name for the module. So when I develop the first version of my file I have to call it circle_a.py. The name of the module then...
34
11276
by: Cuthbert | last post by:
Hi folks, I am trying to find a more efficient way to count "How many bits are '1' in a integer variable?". I still have no idea to count the bits except using a loop and "if" statements. Could you know any other more efficient way? Cuthbert
13
2681
by: André | last post by:
Hi, i'm developping asp.net applications and therefore i use VB.net. I have some questions about best practises. According what i read about class and module and if i understand it right, a module does the same as a class but cannot herite or be herited. 1)Is that right? 2) So i guess this module does exactly the same as the class?
2
11000
by: =?Utf-8?B?c2FtMDFt?= | last post by:
I have a remoting application that was developed on a Windows XP SP2 machine with VS2005 SP1. I finally got everything deployed using Wix 3.0, and it works great. Problem is, when I install the msi on a W23 server SP2, I get the following error: System.Runtime.Remoting.RemotingException: Remoting configuration failed with the exception...
36
3078
by: The Frog | last post by:
Hi Everyone, I am trying to find a solution for handling zipped data without the need to ship / install any DLL files with the database. Does anybody know of code to handle ZIP files that does not require any external references? If I can ship it 'built-in' as either a class module or standard module then that would be perfect. Any help...
11
1848
by: JoeC | last post by:
I am working on a graphics program but my question has nothing to do with graphics but trying to get an algorithm to work. I set graphics from a 16x16 grid to bits of a graphic with: bitData = binTemp * 128 + binTemp * 64 + binTemp * 32 + binTemp * 16 + binTemp * 8 + binTemp * 4 + binTemp * 2 + binTemp; But I want to populate...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.