summaryrefslogtreecommitdiff
path: root/src/phenotypebinary.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/phenotypebinary.cpp')
-rw-r--r--src/phenotypebinary.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/phenotypebinary.cpp b/src/phenotypebinary.cpp
index d16588b..68f9ebf 100644
--- a/src/phenotypebinary.cpp
+++ b/src/phenotypebinary.cpp
@@ -99,3 +99,37 @@ Bu::String Genetic::PhenotypeBinary::toString()
99 return sRet; 99 return sRet;
100} 100}
101 101
102void Genetic::PhenotypeBinary::extractBits( uint32_t &rTarget, int iStart,
103 int iBits )
104{
105 rTarget = 0;
106 if( iBits > sizeof(rTarget)*8 )
107 iBits = sizeof(rTarget)*8;
108
109 // This is pretty much the same problem as copyFrom, so I'm doing it the
110 // same way for now.
111 for( int j = 0; j < iBits; j++ )
112 {
113 int ws = wordWithBit(j+iStart);
114 if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 )
115 rTarget |= (1<<(j%BPW));
116 }
117}
118
119void Genetic::PhenotypeBinary::extractBits( uint64_t &rTarget, int iStart,
120 int iBits )
121{
122 rTarget = 0;
123 if( iBits > sizeof(rTarget)*8 )
124 iBits = sizeof(rTarget)*8;
125
126 // This is pretty much the same problem as copyFrom, so I'm doing it the
127 // same way for now.
128 for( int j = 0; j < iBits; j++ )
129 {
130 int ws = wordWithBit(j+iStart);
131 if( (aGenes[ws]&(1<<((j+iStart)%BPW))) != 0 )
132 rTarget |= (1ll<<(j));
133 }
134}
135