SEARCH YOUR SOLUTION HERE  

Bit Scan Forward and Reverse

I'm writing an app in python, and I'm storing some a lot of data in bitmaps. I need a way to find the first or latest set bit in a 64bit number, and for that I've implemented a small ...

Posted On: Sunday 25th of November 2012 11:33:03 PM Total Views:  371
View Complete with Replies




Related Messages:

Re: struct,long on 64-bit machine   (81 Views)
Neal Becker wrote: > What's wrong with this > type(struct.unpack('l','\00'*8)[0]) > > > Why I am getting 'int' when I asked for 'long' > > This is on python-2.5.1-15.fc8.x86_64 > On my AMD 64 I think int is 64 bits $ python -c "import sys; print sys.maxint" 9223372036854775807 -- Robin Becker
struct,long on 64-bit machine   (90 Views)
What's wrong with this type(struct.unpack('l','\00'*8)[0]) Why I am getting 'int' when I asked for 'long' This is on python-2.5.1-15.fc8.x86_64
Solaris 10 + Sun Studio 12 Pyrhon 2.4.4 64-bit build problem   (99 Views)
I've been trying for days to build 64 bit python with Solaris 10 + Sun Studio 12. Can anyone helpl please. This is how I tried to do build: # ./configure --prefix=/opt/python2.4 --without-gcc --enable-shared checking MACHDEP... sunos5 checking EXTRAPLATDIR... checking for --without-gcc... yes checking for --with-cxx=... no checking for c++... /opt/SUNWspro/bin/CC checking for C++ compiler default output file name... a.out checking whether the C++ compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for gcc... cc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... no checking whether cc accepts -g... yes checking for cc option to accept ANSI C... none needed checking how to run the C preprocessor... /opt/SUNWspro/bin/CC configure: error: C preprocessor "/opt/SUNWspro/bin/CC" fails sanity check See `config.log' for more details. (sorry for the long log file but I'm not sure which part are important) config.log: This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. It was created by python configure 2.4, which was generated by GNU Autoconf 2.59. Invocation command line was $ ./configure --prefix=/opt/python2.4 --without-gcc --enable-shared ## --------- ## ## Platform. ## ## --------- ## hostname = zone2 uname -m = sun4u uname -r = 5.10 uname -s = SunOS uname -v = Generic_118833-36 /usr/bin/uname -p = sparc /bin/uname -X = System = SunOS Node = zone2 Release = 5.10 KernelID = Generic_118833-36 Machine = sun4u BusType = Serial = Users = OEM# = 0 Origin# = 1 NumCPU = 1 /bin/arch = sun4 /usr/bin/arch -k = sun4u /usr/convex/getsysinfo = unknown hostinfo = unknown /bin/machine = unknown /usr/bin/oslevel = unknown /bin/universe = unknown PATH: /usr/local/bin PATH: /usr/xpg4/bin PATH: /usr/sfw/bin PATH: /opt/SUNWspro/bin PATH: /usr/local/mysql/bin PATH: /usr/ccs/bin PATH: /usr/local/bin PATH: /usr/xpg4/bin PATH: /usr/sfw/bin PATH: /opt/SUNWspro/bin PATH: /usr/local/mysql/bin PATH: /usr/ccs/bin PATH: /usr/local/bin PATH: /usr/xpg4/bin PATH: /usr/sfw/bin PATH: /opt/SUNWspro/bin PATH: /usr/local/mysql/bin PATH: /usr/ccs/bin PATH: /usr/sbin PATH: /usr/bin PATH: /usr/openwin/bin PATH: /usr/sfw/bin PATH: /usr/openwin/bin PATH: /usr/sfw/bin PATH: /usr/openwin/bin PATH: /usr/sfw/bin ## ----------- ## ## Core tests. ## ## ----------- ## configure:1510: checking MACHDEP configure:1655: result: sunos5 configure:1661: checking EXTRAPLATDIR configure:1676: result: configure:1697: checking for --without-gcc configure:1746: result: yes configure:1752: checking for --with-cxx= configure:1773: result: no configure:1792: checking for c++ configure:1818: result: /opt/SUNWspro/bin/CC configure:1858: checking for C++ compiler default output file name configure:1861: /opt/SUNWspro/bin/CC -L/opt/SUNWmlib/lib -lrt -lm conftest.cc >&5 configure:1864: $ = 0 configure:1910: result: a.out configure:1915: checking whether the C++ compiler works configure:1921: ./a.out configure:1924: $ = 0 configure:1941: result: yes configure:1948: checking whether we are cross compiling configure:1950: result: no configure:1953: checking for suffix of executables configure:1955: /opt/SUNWspro/bin/CC -o conftest -L/opt/SUNWmlib/lib -lrt -lm conftest.cc >&5 configure:1958: $ = 0 configure:1983: result: configure:2057: checking for gcc configure:2083: result: cc configure:2327: checking for C compiler version configure:2330: cc -V &5 cc: Sun C 5.9 SunOS_sparc Patch 124867-01 2007/07/12 usage: cc [ options] files. Use 'cc -flags' for details configure:2333: $ = 1 configure:2356: checking for C compiler default output file name configure:2359: cc -O2 -L/opt/SUNWmlib/lib -lrt -lm conftest.c >&5 configure:2362: $ = 0 configure:2408: result: a.out configure:2413: checking whether the C compiler works configure:2419: ./a.out configure:2422: $ = 0 configure:2439: result: yes configure:2446: checking whether we are cross compiling configure:2448: result: no configure:2451: checking for suffix of executables configure:2453: cc -o conftest -O2 -L/opt/SUNWmlib/lib -lrt -lm conftest.c >&5 configure:2456: $ = 0 configure:2481: result: configure:2487: checking for suffix of object files configure:2508: cc -c -O2 conftest.c >&5 configure:2511: $ = 0 configure:2533: result: o configure:2537: checking whether we are using the GNU C compiler configure:2561: cc -c -O2 conftest.c >&5 "conftest.c", line 15: undefined symbol: choke "conftest.c", line 15: syntax error before or at: me cc: acomp failed for conftest.c configure:2567: $ = 2 configure: failed program was: | /* confdefs.h. */ | | #define _GNU_SOURCE 1 | #define _NETBSD_SOURCE 1 | #define __BSD_VISIBLE 1 | #define _BSD_TYPES 1 | #define _XOPEN_SOURCE 500 | #define _POSIX_C_SOURCE 200112L | /* end confdefs.h. */ | | int | main () | { | #ifndef __GNUC__ | choke me | #endif | | ; | return 0; | } configure:2593: result: no configure:2599: checking whether cc accepts -g configure:2620: cc -c -g conftest.c >&5 configure:2626: $ = 0 configure:2630: test -z || test ! -s conftest.err configure:2633: $ = 0 configure:2636: test -s conftest.o configure:2639: $ = 0 configure:2650: result: yes configure:2667: checking for cc option to accept ANSI C configure:2737: cc -c -O2 conftest.c >&5 "conftest.c", line 53: warning: statement not reached configure:2743: $ = 0 configure:2747: test -z || test ! -s conftest.err configure:2750: $ = 0 configure:2753: test -s conftest.o configure:2756: $ = 0 configure:2774: result: none needed configure:2792: cc -c -O2 conftest.c >&5 "conftest.c", line 2: warning: old-style declaration or incorrect type for: choke "conftest.c", line 2: syntax error before or at: me "conftest.c", line 3: warning: old-style declaration or incorrect type for: me cc: acomp failed for conftest.c configure:2798: $ = 2 configure: failed program was: | #ifndef __cplusplus | choke me | #endif configure:2939: checking how to run the C preprocessor configure:3057: result: /opt/SUNWspro/bin/CC configure:3081: /opt/SUNWspro/bin/CC conftest.c "conftest.c", line 15: Error: Syntax is not defined. "conftest.c", line 15: Error: "," expected instead of "end of file". "conftest.c", line 15: Error: Use ";" to terminate declarations. 3 Error(s) detected. configure:3087: $ = 3 configure: failed program was: | /* confdefs.h. */ | | #define _GNU_SOURCE 1 | #define _NETBSD_SOURCE 1 | #define __BSD_VISIBLE 1 | #define _BSD_TYPES 1 | #define _XOPEN_SOURCE 500 | #define _POSIX_C_SOURCE 200112L | /* end confdefs.h. */ | #ifdef __STDC__ | # include | #else | # include | #endif | Syntax error configure:3081: /opt/SUNWspro/bin/CC conftest.c "conftest.c", line 15: Error: Syntax is not defined. "conftest.c", line 15: Error: "," expected instead of "end of file". "conftest.c", line 15: Error: Use ";" to terminate declarations. 3 Error(s) detected. configure:3087: $ = 3 configure: failed program was: | /* confdefs.h. */ | | #define _GNU_SOURCE 1 | #define _NETBSD_SOURCE 1 | #define __BSD_VISIBLE 1 | #define _BSD_TYPES 1 | #define _XOPEN_SOURCE 500 | #define _POSIX_C_SOURCE 200112L | /* end confdefs.h. */ | #ifdef __STDC__ | # include | #else | # include | #endif | Syntax error configure:3156: error: C preprocessor "/opt/SUNWspro/bin/CC" fails sanity check See `config.log' for more details. ## ---------------- ## ## Cache variables. ## ## ---------------- ## ac_cv_c_compiler_gnu=no ac_cv_env_CC_set=set ac_cv_env_CC_value=/opt/SUNWspro/bin/cc ac_cv_env_CFLAGS_set=set ac_cv_env_CFLAGS_value=-O2 ac_cv_env_CPPFLAGS_set=set ac_cv_env_CPPFLAGS_value= ac_cv_env_CPP_set=set ac_cv_env_CPP_value=/opt/SUNWspro/bin/CC ac_cv_env_LDFLAGS_set=set ac_cv_env_LDFLAGS_value='-L/opt/SUNWmlib/lib -lrt -lm' ac_cv_env_build_alias_set= ac_cv_env_build_alias_value= ac_cv_env_host_alias_set= ac_cv_env_host_alias_value= ac_cv_env_target_alias_set= ac_cv_env_target_alias_value= ac_cv_exeext= ac_cv_objext=o ac_cv_prog_CPP=/opt/SUNWspro/bin/CC ac_cv_prog_CXX=/opt/SUNWspro/bin/CC ac_cv_prog_ac_ct_CC=cc ac_cv_prog_cc_g=yes ac_cv_prog_cc_stdc= ## ----------------- ## ## Output variables. ## ## ----------------- ## AR='' BASECFLAGS='-# -xc99=all,lib -m64 -H -Xc -c -errtags=yes' BLDLIBRARY='' BLDSHARED='' BUILDEXEEXT='' CC='cc' CCSHARED='' CFLAGS='-O2' CFLAGSFORSHARED='' CONFIGURE_MACOSX_DEPLOYMENT_TARGET='' CONFIG_ARGS=''--prefix=/opt/python2.4' '--without-gcc' '--enable- shared' 'CC=/opt/SUNWspro/bin/cc' 'CFLAGS=-O2' 'CPPFLAGS=' 'CPP=/opt/ SUNWspro/bin/CC' 'LDFLAGS=-L/opt/SUNWmlib/lib -lrt -lm'' CPP='/opt/SUNWspro/bin/CC' CPPFLAGS='' CXX='/opt/SUNWspro/bin/CC' DEFS='' DLINCLDIR='' DLLLIBRARY='' DYNLOADFILE='' ECHO_C='' ECHO_N='-n' ECHO_T='' EGREP='' EXEEXT='' EXPORT_MACOSX_DEPLOYMENT_TARGET='#' EXTRAMACHDEPPATH='' EXTRAPLATDIR='' FRAMEWORKALTINSTALLFIRST='' FRAMEWORKALTINSTALLLAST='' FRAMEWORKINSTALLFIRST='' FRAMEWORKINSTALLLAST='' FRAMEWORKUNIXTOOLSPREFIX='/opt/python2.4' HAVE_GETHOSTBYNAME='' HAVE_GETHOSTBYNAME_R='' HAVE_GETHOSTBYNAME_R_3_ARG='' HAVE_GETHOSTBYNAME_R_5_ARG='' HAVE_GETHOSTBYNAME_R_6_ARG='' INSTALL_DATA='' INSTALL_PROGRAM='' INSTALL_SCRIPT='' INSTSONAME='' LDFLAGS='-L/opt/SUNWmlib/lib -lrt -lm' LDLAST='' LDLIBRARY='' LDLIBRARYDIR='' LDSHARED='' LIBC='' LIBM='' LIBOBJS='' LIBRARY='' LIBS='' LIBTOOL_CRUFT='' LINKCC='' LINKFORSHARED='' LN='' LTLIBOBJS='' MACHDEP='sunos5' MACHDEP_OBJS='' MAINOBJ='python.o' OBJEXT='o' OPT='' OTHER_LIBTOOL_OPT='' PACKAGE_BUGREPORT='http://www.python.org/python-bugs' PACKAGE_NAME='python' PACKAGE_STRING='python 2.4' PACKAGE_TARNAME='python' PACKAGE_VERSION='2.4' PATH_SEPARATOR=':' PYTHONFRAMEWORK='' PYTHONFRAMEWORKDIR='no-framework' PYTHONFRAMEWORKINSTALLDIR='' PYTHONFRAMEWORKPREFIX='' RANLIB='' RUNSHARED='' SGI_ABI='' SHELL='/bin/bash' SHLIBS='' SIGNAL_OBJS='' SO='' SOVERSION='1.0' SRCDIRS='' THREADHEADERS='' THREADOBJ='' TRUE='' UNICODE_OBJS='' UNIVERSALSDK='' USE_SIGNAL_MODULE='' USE_THREAD_MODULE='' VERSION='2.4' ac_ct_CC='cc' ac_ct_RANLIB='' bindir='${exec_prefix}/bin' build_alias='' datadir='${prefix}/share' exec_prefix='NONE' host_alias='' includedir='${prefix}/include' infodir='${prefix}/info' libdir='${exec_prefix}/lib' libexecdir='${exec_prefix}/libexec' localstatedir='${prefix}/var' mandir='${prefix}/man' oldincludedir='/usr/include' prefix='/opt/python2.4' program_transform_name='s,x,x,' sbindir='${exec_prefix}/sbin' sharedstatedir='${prefix}/com' sysconfdir='${prefix}/etc' target_alias='' ## ----------- ## ## confdefs.h. ## ## ----------- ## #define _BSD_TYPES 1 #define _GNU_SOURCE 1 #define _NETBSD_SOURCE 1 #define _POSIX_C_SOURCE 200112L #define _XOPEN_SOURCE 500 #define __BSD_VISIBLE 1 configure: exit 1 -------end of config.log------------------------------------------------------------------------
128 or 96 bit integer types?   (93 Views)
Is there build-in or third party support for large integer types, such as 96 or 128 bits in size I require such large sizes for precision issues (nanoseconds).
converting 64-bit fixed-point to float   (115 Views)
Hi Group, troubles with converting signed 32.32, little-endian, 2's complement back to floating point. I have been trying to brew it myself. I am running Python 2.5 on a Mac. Here is the C-code I have been trying to leverage: double FPuint8ArrayToFPDouble(uint8 *buffer, int startIndex) { uint32 resultDec = 0; uint32 resultWh = 0; int i; for(i = 0; i < 4; i++) { resultDec += (uint32)buffer[startIndex + i] * pow(2, (i*8)); resultWh += (uint32)buffer[startIndex + i + 4] * pow(2, (i*8)); } return ( (double)((int)resultWh) + (double)(resultDec)/4294967296.0 ); } Here is my version in Python, with some test code built in: from ctypes import * def conv64(input): input1=[0]*8 input1[0]=c_ushort(input[0]) input1[1]=c_ushort(input[1]) input1[2]=c_ushort(input[2]) input1[3]=c_ushort(input[3]) input1[4]=c_ushort(input[4]) input1[5]=c_ushort(input[5]) input1[6]=c_ushort(input[6]) input1[7]=c_ushort(input[7]) #print input1[0].value, input1[1].value,input1[2].value,input1[3].value #print input1[4].value,input1[5].value,input1[6].value,input1[7].value #print resultDec=c_ulong(0) resultWh=c_ulong(0) for i in range(4): dec_c=c_ulong(input1[i].value) Wh_c=c_ulong(input1[i+4].value) resultDec.value=resultDec.value+dec_c.value*2**(i*8) resultWh.value=resultWh.value+Wh_c.value*2**(i*8) conval=float(int(resultWh.value))+float(resultDec.value)/4294967296.0 #print conval return conval #tabs got messed up bringing this into MacSoup #these are 64-bit fixed point format (signed 32.32, little-endian, 2's complement) #should be -1 conv64_0=[0, 0, 0, 255, 255, 255, 255, 255] #should be 0 conv64_1=[0, 0, 0, 0, 0, 0, 0, 0] #should be 0.20000 conv64_1_2=[51, 51, 51, 51, 0, 0, 0, 0] #should be 1 conv64_2=[0, 0, 0, 0, 1, 0, 0, 0] #should be 2 conv64_3=[0, 0, 0, 0, 2, 0, 0, 0] #should be 298.15 conv64_4=[102, 102, 102, 38, 42, 1, 0, 0] #should be -0.2 conv64_5=[205,204,204,204,255,255,255,255] output0=conv64(conv64_0) print "output should be -1 is "+str(output0) output1=conv64(conv64_1) print "output should be 0 is "+str(output1) output1_2=conv64(conv64_1_2) print "output should be 0.2 is "+str(output1_2) output2=conv64(conv64_2) print "output should be 1 is "+str(output2) output3=conv64(conv64_3) print "output should be 2 is "+str(output3) output4=conv64(conv64_4) print "output should be 298.15 is "+str(output4) output5=conv64(conv64_5) print "output should be -0.2 is "+str(output5) Finally, here is the output I get from my code: >>> output should be -1 is 4294967296.0 output should be 0 is 0.0 output should be 0.2 is 0.199999999953 output should be 1 is 1.0 output should be 2 is 2.0 output should be 298.15 is 298.15 output should be -0.2 is 4294967295.8
Re: Compiling python extension on amd64 for 32 bit   (96 Views)
Mathias Waack wrote: > Andrew MacIntyre wrote: > >> Mathias Waack wrote: >>> After switching my development environment to 64 bit I've got a >>> problem with a python extension for a 32 bit application. >> {...} >> >>> Ok, thats fine. So why is python complaining Or even more >>> interesting, what do I have to do to compile the code >> Is the Python your toolchain is referencing 32 or 64 bit Based on >> what I can see in pyport.h, I'd guess that you're finding a 64 bit >> Python (ie SIZEOF_LONG == 8). > > There is no such thing as "the Python". A biarch environment offers > both the 32 bit and the 64 bit versions of each library. And unique > headers, because its assumed that the headers are independent of the > architecture. Because of the -m32 Flag the pyport.h is used within a > 32 bit env. Every Python installation has an architecture dependent header (pyconfig.h), unless a vendor specifically creates a replacement which neutralises this; that header contains the definition (SIZEOF_LONG) that triggers your problem. -- ------------------------------------------------------------------------- Andrew I MacIntyre "These thoughts are mine alone..." E-mail: andymac@bullseye.apana.org.au (pref) | Snail: PO Box 370 andymac@pcug.org.au (alt) | Belconnen ACT 2616 Web: http://www.andymac.org/ | Australia
how to call bluebit...   (83 Views)
helo... i'm so glad can join to this website... i want to ask.. how to import bluebit matrik calculator that result of singular value decomposition (SVD) in python programming.. thank's for your answer. -- View this message in context: http://www.nabble.com/how-to-call-bl...html#a11575281 Sent from the Python - python-list mailing list archive at Nabble.com.
Write bits in file   (89 Views)
Hi I have a specific format and I need binary representation. Does Python have some built-in function which will, for instance, represent number 15 in exactly 10 bits...
ANN: BOTEC 0.2 -- An astrophysical and orbital mechanics calculator   (72 Views)
Summary BOTEC is a simple astrophysical and orbital mechanics calculator, including a database of all named Solar System objects. Overview BOTEC is intended as a simple but useful calculator to assist with making astrophysical, orbital mechanics, and space navigation calculations. ...
how to get the thighest bit position in big integers?   (200 Views)
I'm using python to develop some proof-of-concept code for a cryptographic application. My code makes extended use of python's native bignum capabilities. In many cryptographic applications there is the need for a function 'get_highest_bit_num' that returns the position number ...
Re: OS 10.5 build 64 bits   (81 Views)
Hi Robin, On 2008-10-23 17:55, Robin Becker wrote: > I'm trying to build Python from the unix sources on an OS 10.5 machine. > This is because we're getting strange faults when using the built in > python 2.5 together ...
Python on Windows XP 64-bit: python not found in registry   (156 Views)
After first trying to install the beta of Python 2.6 on my Windows XP 64-bit machine I finally succeeded installing 2.5.2. But I still have a some problem: Installing iPython, PIL, easy_install etc fails saying that python.exe cannot be found ...
Arbitrary precision integer arithmetic: ceiling?   (126 Views)
I need to apply the ceiling function to arbitrary sized (long) integers. However, division automatically returns the type of its operands, so that, for example: math.ceil(7/4) returns 1. I can use float, as in: math.ceil(7/float(4)), except that for very large ...
MySQLdb and compatibility with vista 64 bits   (100 Views)
, I try to install mysqldb on windows vista 64bits but there is a failure when i try to import mysqldb in python 2.5 : "DLL load failed with error code 193" Is there a solution to this problem ...
Loading an exe icon into a pixmap/bitmap   (83 Views)
I've been searching for a way to load an icon from an executable into something that I can eventually display either through pygame or pygtk. I've tried the stuff found at http://groups.google.com/group/comp....f38c1ced504e43 but the tests just output all black (not ...
Subprocess and 16-bit FORTRAN   (89 Views)
, For the past year I've been building an XP Python/wxPython shell of sorts for several dozen command line FORTRAN tools developed for various material science problems. Given how the methods and how-to's have been lost to but the ...
write unsigned integer 32 bits to socket   (92 Views)
hi i want to send unsigned 32 bit integer to socket, and looking for something equivalent to this method... http://livedocs.adobe.com/flex/2/lan...teUnsignedInt( ) is there such method / library available in python! this is as far as i have gotten along >>> ...
Re: 32 bit or 64 bit?   (129 Views)
On Jun 18, 10:00pm, "ram.rac...@gmail.com" wrote: > On Jun 18, 3:02am, Phil Hobbs > > wrote: > > ram.rac...@gmail.com wrote: > > > > That was suggested. Problem is, that sometimes the velocities are near > > > ...
bit parsing from file   (66 Views)
, I'm tring to make a cutting script. The problem is the following, i have a sample pattern, for example :'11101110' (0xEE) That is the sign of the data begining. How can i cut a file if the byte stepping ...
idiom to ask if you are on 32 or 64 bit linux platform?   (129 Views)
, I've got a ctypes wrapper to some code which seems to be different when compiled on 32 bit linux compared to 64 bit linux. For the windows version I can use sys.platform == 'win32' versus 'linux2' to decide ...