If there're a number of rows in a column of table, each row with binary values, how can one do a logical OR on all of them (using PHP to retrieve the binary data from a SQL server)? [see baby-appendix below for a description of OR]
As an example, assume my_table has a column called 'bin' with 5 rows:
00010001
10000100
00001000
00111101
00010101
The OR of the above would be:
10111101
I'd like my PHP code to do the above functionality. Here's my thought (in pseudo-code):
- set $n=0
- fetch all the rows under 'bin'
- compare the n'th value of all of the rows with '1' (so when $n=0, only the very left bit (Most Sig. Bit) of all the rows are compared)
- if TRUE then the n'th bit of answer is '1', else '0'
- $n++
- jump back to the comparison step
The 3rd and 4th steps are the ones that are bothering me... Any help would be greatly appreciated.
baby-appendix:
OR: a logical gate used in electrical circuits. Its functionality is simple:
0 OR 0 -> 0
0 OR 1 -> 1
1 OR 0 -> 1
1 OR 1 -> 1
So when n digits are OR'd, if one of them has a value of '1' then the answer is '1', otherwise it's '0'.