duytin Posted April 19, 2007 Share Posted April 19, 2007 Dear All, I want to make a bitwise function but I don't know how to make it. Suggest that I want to make function my_bitwise($a,$b). I want the result as: Bits that are set in $a but not $b, and not vice versa. For example: $a=1010 ; $b=1100 I want result my_bitwise($a,$b)=0010. Pls hepl me! Thks in advance! Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/ Share on other sites More sharing options...
genericnumber1 Posted April 19, 2007 Share Posted April 19, 2007 http://www.php.net/manual/en/language.operators.bitwise.php edit: oh sorry, didn't really read your question all the way through Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-232913 Share on other sites More sharing options...
Barand Posted April 19, 2007 Share Posted April 19, 2007 <?php $a= 10 ; #1010 $b= 12 ; #1100 printf ('%04s', decbin($a & ~$b)); //--> 0010 ?> A and not B Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-232923 Share on other sites More sharing options...
duytin Posted April 19, 2007 Author Share Posted April 19, 2007 I want to say thanks very much to you! ;D <?php $a= 10 ; #1010 $b= 12 ; #1100 printf ('%04s', decbin($a & ~$b)); //--> 0010 ?> A and not B Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-232939 Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 How I can define a constant of an array? Foe example, I want to declaire: define ("A",array(1,2,3)); (The result I received is a error message ) Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238785 Share on other sites More sharing options...
genericnumber1 Posted April 26, 2007 Share Posted April 26, 2007 You cant, now that was simple. you could serialize() an array in I guess... Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238839 Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Dear Genericnumber1, Can you tell me more detail on serialize()... ??? Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238842 Share on other sites More sharing options...
genericnumber1 Posted April 26, 2007 Share Posted April 26, 2007 http://www.php.net/serialize but it's a pretty big pain just for a constant array Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238843 Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 How I can define a constant of an array? Foe example, I want to declaire: define ("A",array(1,2,3)); (The result I received is a error message ) why would you want to do that? Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238849 Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Hi boo_lolly, I'm trying to make a program this solve the Sudoku. In this programe, I use the array : array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)) many times in the program. So, I want to make a constant (not a variable!) represent this array. Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238859 Share on other sites More sharing options...
duytin Posted April 26, 2007 Author Share Posted April 26, 2007 Hi boo_lolly, I'm trying to make a program this solve the Sudoku. In this programe, I use the array : array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)) many times in the program. So, I want to make a constant (not a variable!) represent this array. Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238860 Share on other sites More sharing options...
boo_lolly Posted April 26, 2007 Share Posted April 26, 2007 have you tried making this array a variable? $array = array(pow(2,1),pow(2,2),pow(2,3),pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,,pow(2,9)); Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-238869 Share on other sites More sharing options...
duytin Posted April 27, 2007 Author Share Posted April 27, 2007 No problem when I use a variable, but it's not a variable naturally!!! Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-239509 Share on other sites More sharing options...
duytin Posted May 2, 2007 Author Share Posted May 2, 2007 Hi All, I want to get an array of data from the input of the user, for example: X11= 1, X12=5, ....,X99=6. I can make with an input apart but I don't know how to make with an array X[j]! Pls help me! :'( Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-243174 Share on other sites More sharing options...
trq Posted May 2, 2007 Share Posted May 2, 2007 Pardon? Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-243176 Share on other sites More sharing options...
duytin Posted May 3, 2007 Author Share Posted May 3, 2007 For example, I want to write a PHP scrip which will: 1. Display an "0" 9X9 sudoku (default value 0 for all 81 squares). 2. The user will input some data in some squares, for example: square(1,1)=1, square(2,3)=5... 3. Transfer all 81 values of the Sudoku in an array, for example: for ($i=1;$i<=9;$i++) Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-244041 Share on other sites More sharing options...
duytin Posted May 3, 2007 Author Share Posted May 3, 2007 For example, I want to write a PHP scrip which will: 1. Display an "0" 9X9 sudoku (default value 0 for all 81 squares). 2. The user will input some data in some squares, for example: square(1,1)=1, square(2,3)=5... 3. Transfer all 81 values of the Sudoku in an array, for example: for ($i=1;$i<=9;$i++) { for ($j=1;$j<=9;$j++) { Sudoku[$i][$j]=square($i,$j); } } 4. After that, I will write a program to solve the Sudoku. Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-244052 Share on other sites More sharing options...
Barand Posted May 3, 2007 Share Posted May 3, 2007 the form <form method='post'> <?php for ($r=0; $r<9; $r++) { for ($c=0; $c<9; $c++) { echo "<input type='text' name='sudoku[$r][$c]' size='3' value='' />"; } echo '<br>'; } echo "<input type='submit' name='action' value='Submit'>"; ?> </form> Process with $sudoku = $_POST['sudoku']; Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-244134 Share on other sites More sharing options...
duytin Posted May 5, 2007 Author Share Posted May 5, 2007 Thk u, teacher Barand! By the way, it seems that there's not remainder function in the PHP? ??? For example: remainder of 5/3 is 2. Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-245818 Share on other sites More sharing options...
genericnumber1 Posted May 5, 2007 Share Posted May 5, 2007 there's a modulus operator... 5 % 3 is 2 Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-245995 Share on other sites More sharing options...
duytin Posted May 5, 2007 Author Share Posted May 5, 2007 Thks. I'm Link to comment https://forums.phpfreaks.com/topic/47696-bitwise-operator/#findComment-246011 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.