pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Bitwise operation
4+ messages / 3 participants
[nested] [flat]

* Bitwise operation
@ 2003-06-30 12:28  Rudi Starcevic <rudi@oasis.net.au>
  0 siblings, 2 replies; 4+ messages in thread

From: Rudi Starcevic @ 2003-06-30 12:28 UTC (permalink / raw)
  To: pgsql-sql


Hi,

I'm learning to use Postgresql's bitwise operator's as I'm interested
in building super fast search's based on user selections in web forms.

So far so good but I have just lost it a little so I thought I'd post.
Please growl at me if I'm asking on the wrong list :-)

I understand this:

SELECT 111 & 11 = 11

but not this

SELECT 1111 & 111 = 71

I was expecting the second example to be 

SELECT 1111 & 111 = 111

Hmm ...

Maybe I should search on the web for some more info on how to 
understand this logic.
Math was never my strongest I was always better at creative writing.

Any advice much appreciated.
Thanks
Best Regards
Rudi.










^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Bitwise operation
@ 2003-06-30 12:36  Hubert Lubaczewski <hubert.lubaczewski@eo.pl>
  parent: Rudi Starcevic <rudi@oasis.net.au>
  1 sibling, 0 replies; 4+ messages in thread

From: Hubert Lubaczewski @ 2003-06-30 12:36 UTC (permalink / raw)
  To: Rudi Starcevic <rudi@oasis.net.au>; +Cc: pgsql-sql

On Mon, 30 Jun 2003 22:28:15 +1000
"Rudi Starcevic" <rudi@oasis.net.au> wrote:

> SELECT 1111 & 111 = 71
> I was expecting the second example to be 
> SELECT 1111 & 111 = 111

hmm ..:
let's see:
dec(1111) is bin(10001010111)
dec(111)  is bin(00001101111)

so, when we'll "AND" them:
1111 :  10001010111 
111  :  00001101111 
-------------------  
        00001000111 : dec: 71 

quite reasonable, isn't it?

depesz



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Bitwise operation
@ 2003-06-30 12:42  Bruno Wolff III <bruno@wolff.to>
  parent: Rudi Starcevic <rudi@oasis.net.au>
  1 sibling, 1 reply; 4+ messages in thread

From: Bruno Wolff III @ 2003-06-30 12:42 UTC (permalink / raw)
  To: Rudi Starcevic <rudi@oasis.net.au>; +Cc: pgsql-sql

On Mon, Jun 30, 2003 at 22:28:15 +1000,
  Rudi Starcevic <rudi@oasis.net.au> wrote:
> 
> Hi,
> 
> I'm learning to use Postgresql's bitwise operator's as I'm interested
> in building super fast search's based on user selections in web forms.
> 
> So far so good but I have just lost it a little so I thought I'd post.
> Please growl at me if I'm asking on the wrong list :-)
> 
> I understand this:
> 
> SELECT 111 & 11 = 11
> 
> but not this
> 
> SELECT 1111 & 111 = 71
> 
> I was expecting the second example to be 
> 
> SELECT 1111 & 111 = 111

In the above examples the numbers are decimal values.

Maybe you wanted to do something like the following:

area=> select b'1111' & b'0111';
 ?column?
----------
 0111
(1 row)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Bitwise operation
@ 2003-06-30 23:48  Rudi Starcevic <rudi@oasis.net.au>
  parent: Bruno Wolff III <bruno@wolff.to>
  0 siblings, 0 replies; 4+ messages in thread

From: Rudi Starcevic @ 2003-06-30 23:48 UTC (permalink / raw)
  To: ; +Cc: pgsql-sql

  Bruno,Hubert,

Thanks.
It's all crystal clear now.

Now I can keep moving on with my app.

If all goes well I hope to add a 'techdoc' on how to do this.
I've found documents from other DBMS on using Bitwise operations
but not PG.

Cheers
Rudi.

Bruno Wolff III wrote:

>On Mon, Jun 30, 2003 at 22:28:15 +1000,
>  Rudi Starcevic <rudi@oasis.net.au> wrote:
>  
>
>>Hi,
>>
>>I'm learning to use Postgresql's bitwise operator's as I'm interested
>>in building super fast search's based on user selections in web forms.
>>
>>So far so good but I have just lost it a little so I thought I'd post.
>>Please growl at me if I'm asking on the wrong list :-)
>>
>>I understand this:
>>
>>SELECT 111 & 11 = 11
>>
>>but not this
>>
>>SELECT 1111 & 111 = 71
>>
>>I was expecting the second example to be 
>>
>>SELECT 1111 & 111 = 111
>>    
>>
>
>In the above examples the numbers are decimal values.
>
>Maybe you wanted to do something like the following:
>
>area=> select b'1111' & b'0111';
> ?column?
>----------
> 0111
>(1 row)
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>  
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2003-06-30 23:48 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-06-30 12:28 Bitwise operation Rudi Starcevic <rudi@oasis.net.au>
2003-06-30 12:36 ` Hubert Lubaczewski <hubert.lubaczewski@eo.pl>
2003-06-30 12:42 ` Bruno Wolff III <bruno@wolff.to>
2003-06-30 23:48   ` Rudi Starcevic <rudi@oasis.net.au>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox