Re: [PHP] Re: Binary mah

2004-06-11 Thread Knightking
On Thu, 10 Jun 2004 20:08:08 -0700, Justin Patrin  
[EMAIL PROTECTED] wrote:

Mark wrote:
[snip]
I'm not sure what's wrong with the code you have, but for the 4-digit  
one you have:

$packed = 4-bit var with ABCD encoded in it
$a = $packed  1;
$b = $packed  2;
$c = $packed  4;
$d = $packed  8;
Just as a side tip, I highly recommend using hexadecimal for bitwise  
functions where possible, i.e.:
$a = $packed  0x1;
$b = $packed  0x2;
$c = $packed  0x4;
$d = $packed  0x8;
$e = $packed  0x10;
$f = $packed  0x20;
$g = $packed  0x40;
$h = $packed  0x80;
$i = $packed  0x100;

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Re: Binary mah

2004-06-11 Thread Justin Patrin
Knightking wrote:
On Thu, 10 Jun 2004 20:08:08 -0700, Justin Patrin  
[EMAIL PROTECTED] wrote:

Mark wrote:
[snip]

I'm not sure what's wrong with the code you have, but for the 4-digit  
one you have:

$packed = 4-bit var with ABCD encoded in it
$a = $packed  1;
$b = $packed  2;
$c = $packed  4;
$d = $packed  8;
Just as a side tip, I highly recommend using hexadecimal for bitwise  
functions where possible, i.e.:
$a = $packed  0x1;
$b = $packed  0x2;
$c = $packed  0x4;
$d = $packed  0x8;
$e = $packed  0x10;
$f = $packed  0x20;
$g = $packed  0x40;
$h = $packed  0x80;
$i = $packed  0x100;

Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
That's a lot easier to see the progression. Functionally no different 
than using decimal, but easier to type and verify. ;-)

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: Binary mah

2004-06-10 Thread Justin Patrin
Mark wrote:
Hey gang,
I've got a complex algorithm that I'm trying to work out. I'm trying
to store and retrieve a set of switches in a decimal representation
of a binary number. I have four checkboxes, call them A, B, C, and D.
They can be represented by a (decimal) number from 0 to 15 in binary
( to ). I need to be able to store and retrieve this set of
data.
I've got the script to store it, and I thought I had the script to
retrieve the data, but I can't seem to get the checkboxes to actually
be checked (or not) depending on the value in the database.
I'm not sure what's wrong with the code you have, but for the 4-digit 
one you have:

$packed = 4-bit var with ABCD encoded in it
$a = $packed  1;
$b = $packed  2;
$c = $packed  4;
$d = $packed  8;
I don't like dealing with the data this way, but the program I'm
interacting with requires it.
The script below is used to handle a number of data elements on the
page.
$pagevars is an array of the variables on the page, and the table
they are located in.
set_val(a,b) puts the values in array a into the variables listed in
array b.
form_element(a,b) is a function that returns a form element of type a
(CB, TB) with the variable a. So form_element(CB,var) returns the
following:
INPUT TYPE=CHECKBOX NAME=var /
If the value is 1 or on, CHECKED will be added.
Here's the script:
--- START CORE.PHP ---
?php
include(../functions.inc);
include(menu.html);
$pagevars=array(statistics=array(StatFlags,StatFiles,StatMail,STF_Hours,STM_Hours));
if (isset($_POST['submit'])) {
$stat=$_POST['stat'];
for ($i=0;$i4;$i++) {
$t[$i]=isset($stat[$i])?1:0;
}
$stat=implode(,$t);
$StatFlags=bindec($stat);
$_POST['StatFlags']=$StatFlags;
unset($_POST['stat']);
if (!set_val($_POST,$pagevars)) {
  echo data not written to database. Contact system administrator;
}
}
$page_var_vals=get_vars($pagevars);
if (is_array($page_var_vals)) {
extract($page_var_vals);
}
echo StatFlags:$StatFlagsBR;
$stat=preg_split('//', str_pad(decbin($StatFlags), 4, 0,
STR_PAD_LEFT), -1, PREG_SPLIT_NO_EMPTY);
for ($i=0;$i4;$i++) {
$stat[$i]=($stat[$i]==1)?on:;
}
debug($stat);
?
H1Statistics/H1
  FORM METHOD=POST ACTION=?php echo $_SERVER['PHP_SELF'];
?
p?php form_element(CB,stat[0]); ?Save statistics to a
file periodically
   Every ?php form_element(TB,STF_Hours); ?hours/p
pSave in: ?php form_element(TB,StatFiles); ?/p
p?php form_element(CB,stat[1]); ?Email statistics
periodically
   Every ?php form_element(TB,STM_Hours); ?hours/p
pSend to: ?php form_element(TB,StatMail); ?/p
p?php form_element(CB,stat[2]); ?Automatically open
the statistics window at startup/p
p?php form_element(CB,stat[3]); ?Collect statistics
about mail sent by local users/p
pSystem Messages/p
pSystem reporting level:
SELECT NAME=
  option value=0
0 - No messages
  /option
  option value=1
1 - Urgent messages
  /option
  option value=2
2 - Significant messages
  /option
  option value=3
3 - Normal messages
  /option
  option value=4
4 - Informational messages
  /option
  option value=5
5 - Debugging messages
  /option
/SELECT/p
pNumber of messages to store: ?php form_element(TB,);
?/p
p?php form_element(CB,); ? Automatically open the
system messages window on startup/p
INPUT TYPE=SUBMIT NAME=submit VALUE=Save /
INPUT TYPE=Reset VALUE=Cancel /
/form
/body
/html
--- END CORE.PHP ---
=
Mark Weinstock
[EMAIL PROTECTED]
***
You can't demand something as a right unless you are willing to fight to death to 
defend everyone else's right to the same thing.
***
	
		
__
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php