NoLandsMan Posted June 18, 2014 Share Posted June 18, 2014 Hi guys, First time poster but very old lurker on this forum. I'm looking for a way to crosseover 2 binary floating numbers or a way to use a bitwise function ( bitShift or bitOR ) on a float. e.g: _Crossover(a=0.0101,b=0.1011) = 0.0111 or 0.1001 ( takes the gene 01 from number a and 11 from number b and vise versa ) Please let me know if you have any ideas or if you need any clarifications. Link to comment Share on other sites More sharing options...
jchd Posted June 18, 2014 Share Posted June 18, 2014 That doesn't make any sense: there is no way to perform bitwise operations on a decimal float. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
RichardL Posted June 19, 2014 Share Posted June 19, 2014 Hi NoLandsMan, I'm not sure exactly what you mean either, but, assume you have some values, you know how they are stored as binary, and you want to read and set some bits. A similar situation to me wanting to convert 64-bit float to 32-bit float as below. You should be able to lift some moves out of this. Richard. expandcollapse popupFunc Float64_2Int_to_Float($iInt32MS, $iInt32LS) #cs Given a 64bit float, as 2 integers this converts to a 32 bit float and returns the value as an AutoIt float (which is probably 32-bit). This is therefore ignoring the extra range and precision available. This is not even complete to that level. $iInt32LS is ignored. This means we are using a 20 bit mantissa, having ignored the next 3 bits that are in the LS DWord. Results below agree with with http://babbage.cs.qc.cuny.edu/IEEE-754.old/64bit.html (This is the MS half of a 64 bit float, being converted via 32 bit float routine and checked against a 64-bit float web-site.) Examples $iInt32MS $iInt32LS 3f800000 0 0.0078125 3fc00000 0 0.1250000 3fe00000 0 0.5000000 3ff00000 0 1.0000000 40000000 0 2.0000000 78000000 0 2.0000000 40080000 0 3.0000000 40100000 0 4.0000000 40200000 0 8.0000000 40400000 0 32.0000000 40800000 0 512.0000000 41000000 0 131072.0000000 42000000 0 8589934592.0000000 44000000 0 36893488147419103000.0000000 #ce Dim $iSign1B Dim $iExp Dim $iMant Dim $iValu2 Dim $iValu3 Dim $fValu $iValu2 = $iInt32MS ; Get the sign bit and the first bit of the ; exponent that's common to F32 and F64 $iSign1B = BitAND($iValu2, 0xC0000000) ; Get the rest of the exponent (10 bits) ; but we only want last 7 of those 10 bits $iExp = BitAND($iValu2, 0x07F00000) ; Shift the exponent up, $iExp = BitShift($iExp, -3) ; Get the mantissa (remaining 20 bits) $iMant = BitAND($iValu2, 0x000FFFFF) ; Shift it up 3, leaving 3 ls bits zero $iMant = BitShift($iMant, -3) ; We should bring in the other 3 bits from the 2nd ; 32 bit dword. Probably insignificant $iValu3 = BitOR($iSign1B, $iExp, $iMant) $fValu = _WinAPI_IntToFloat($iValu3) Return $fValu EndFunc Link to comment Share on other sites More sharing options...
NoLandsMan Posted June 19, 2014 Author Share Posted June 19, 2014 First of all thank you very much for your interest in helping me. I'm very aware of the confusion but it doesnt have to be a bitwise operation , I want to perform a genome crossover between 2 numbers, Say these numbers were ints represented on 4 bits like 12 : 1100 and 3 : 0011 the crossover between them would be 0: 0000 and 15 : 1111 in this case the crossover can be done with a bitwise operation like bitAND or whatever.. Since the problem here is that the numbers are floats and no bitwise operation can be done,is there any way to code a crossover using strings ? How do you transform a binary float to a string and vice versa ? here's a clearer example : in : a = 0.00110011.. b = 0.10101010.. out : a(X)b =0.10110010.. b(X)a =0.00100010.. Link to comment Share on other sites More sharing options...
Mat Posted June 19, 2014 Share Posted June 19, 2014 I did this for a school project many years ago. This is in C, and written by a younger, very unexperienced, me... The important bits are the functions you can find here, such as: aalflt aal__bitandd( aalflt a, aalflt b ) { aalflt r; long long ai, bi, ri; ai = *( long long* )&a; bi = *( long long* )&b; ri = AALFLT_MAKE( AALFLT_EXP( ai ) & AALFLT_EXP( bi ), ai & bi & AALFLT_MANT_MASK ); r = *( aalflt* )&ri; return r; } And then the definitions here. Needless to say I take one look at that code now and say: "You can't do that, you've completely ignored denormalised floats and other special cases", but it should give you a vague idea. I've found that this page gives the most comprehensive information on IEEE754, which you will have to understand to have any idea what the code above does. AutoIt Project Listing Link to comment Share on other sites More sharing options...
czardas Posted June 19, 2014 Share Posted June 19, 2014 (edited) Interesting link Mat. I don't get this part though: ±0 ÷ ±0 = NaN Edit Think I'm getting it now. My argument goes like this: anything × ±0 = ±0 .: ±0 ÷ ±0 could be anything. Edited June 19, 2014 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
RichardL Posted June 19, 2014 Share Posted June 19, 2014 Looking at it a different way, is the data arrays of floats, and what's wanted is a function that gets given 2 arrays, and a list of indeces? For each index the function swaps over the floats in the arrays? (I can't imagine why genetic data would be floats, when I was at uni DNA was a sequence of one of 3 possible bases, so would think integers more appropriate.) Link to comment Share on other sites More sharing options...
NoLandsMan Posted June 19, 2014 Author Share Posted June 19, 2014 (edited) Looking at it a different way, is the data arrays of floats, and what's wanted is a function that gets given 2 arrays, and a list of indeces? For each index the function swaps over the floats in the arrays? (I can't imagine why genetic data would be floats, when I was at uni DNA was a sequence of one of 3 possible bases, so would think integers more appropriate.) Yes the data is arrays of floats and the function gets 2 data arrays and for the same index on both arrays takes the 2 float values converts them to binary to generate 2 new ones by crossing their genes( in my case a gene is 2 bits like ( 10 ) ) then reconvert the values and insert them back .Usually coding genetic data is done in base 2 but of course it's open to any other suggestions. Currently I'm working on converting the binary floats to strings then do the crossing on the strings ( much easier ) and finally convert the strings back to floats.Whats an easy way to get a binary float to a string value ? Edited June 19, 2014 by NoLandsMan Link to comment Share on other sites More sharing options...
Mat Posted June 19, 2014 Share Posted June 19, 2014 Why are you using floats? You get less bit-pairs in a float than in an integer of equivalent size. Are the floats always between 0 and 1, that would make it a lot easier (though also reduce you to pretty much using integers). Using base 4 would mean each gene is a single digit. NoLandsMan 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
RichardL Posted June 20, 2014 Share Posted June 20, 2014 (edited) To make a function that swaps over array elements is easy. Func SwapArItem(ByRef $A, ByRef $B, $ix) ; Swap over the ix item in array A and B. (Not Tested) Local $tmp $tmp = $A[$ix] $A[$ix] = $B[$ix] $B[$ix] = $tmp EndFunc It should have bounds checking, and you might want to pass in an array of indeces to swap. I think it will work on arrays of any data type, or even mixed mismatching types. Normally the data type is chosen to match the data e.g. float for measured volts. The data-type selects the way the language operates on the data. You don't need floating point arithmetic. Your proposed conversions back and forth further convince me that floats are the wrong type. AutoIt has routines for converting to/from binary and strings. If you go that way you need to see the help and the examples. Are you able to show how the data starts off, show a few lines of the file or whatever the data is before you read it in to a program? How big is it? Edited June 20, 2014 by RichardL Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now