Search the Community
Showing results for tags 'bitwise'.
-
Hi Thanks for your help I'll just describe what I want to do any advice or if you could provide your own example it would really help, thanks again! I have a string holding hex numbers "41495ab3edde720c" and I want to get those values out of the string and represent them as hexadecimal thus 0x41495ab3edde720c, then I want to xor that hex with another hex like 0x41495ab3edde720c ^ 0x1111111111111111 then I want to take the result which will be in this example (50584BA2FCCF631D) and turn it back into a string "50584BA2FCCF631D" I'm not that good with php it seems hard to do this easily?
-
hi all, here's some code for combinations of array values: $words = array(1,2,3,4); $num = count($words); //The total number of possible combinations $total = pow(2, $num); //Loop through each possible combination for ($i = 0; $i < $total; $i++) { //For each combination check if each bit is set for ($j = 0; $j < $total; $j++) { //Is bit $j set in $i? if (pow(2, $j) & $i) echo $words[$j] . ' '; } echo '<br />'; } I understand everything about this except the fact that the array indicies can only be 0-3 for an array with 4 elements like this one. What I'm not understanding is the nested loop for $J. Isn't it obvious that the bitwise outcome will never be = 1 everytime $J rises above 3 (which is the element count) and finishes it's loop? If the outcome was ever = 1 in that scenario, $words[$j] would be undefined and couldn't echo out, right? So the question is, why is this code written the way it is which renders most of the nested loop iterations for $J useless? If this is supposed to be in the math section, please let me know. thanks.