is the bit on or off

From: WindAndWaves (access_at_ngaru.com)
Date: 07/19/04


Date: Mon, 19 Jul 2004 15:11:52 +1200

Dear Gurus

I have been trolling a few news groups, but so far unsuccessful.

I want to know if there is a simple formula that returns TRUE or FALSE for a
given number between 0 - 255. Whether the function returns true or false
depends on whether a particular bit is turned on or off:

e.g,
F(1,1) = true (or <>0) ............... 10000000
F(2,2) = true (or <>0) ............... 01000000
F(4,3) = true (or <>0) ............... 00100000
F(8,4) = true (or <>0) ............... 00010000
F(16,5) = true (or <>0) ............. 00001000
F(16,1) = false (or =0) .............. 00001000
F(17,1) = false (or =0) ............. 10001000
F(128,8) = true (or <>0)........... 00000001

Now, here is the catch... I am looking for a nice formula that is as simple
as possible (e.g. F = A^(B-1)-B). Some basic functions can be used, such as
round and int (taking the integer part), but no advanced (e.g. C++)
functions should be used, as I would like to use the formula in SQL (e.g.
the AND as a boolean operator does not work in SQL).

The SQL could look like this

SELECT * FROM TABLE WHERE ((FIELD^(N-1)-N)=true);

Where Table is random table, FIELD is a number from the table that is
between 0 and 255 and N is a number between 1 and 8.

TIA

- Nicolaas



Relevant Pages

  • Re: is the bit on or off
    ... > I have been trolling a few news groups, but so far unsuccessful. ... as I would like to use the formula in SQL (e.g. ...
    (sci.math)
  • Running Sum / Cumulative Total Graph
    ... I have searched through the news groups and found many threads close to ... cumulative expenses and cumulative invoices so I can compare them ... What I have tried to do is create a runing sum column using the SQL ...
    (comp.databases.ms-access)
  • Re: OO vs. RDB challenge
    ... >>(claiming that SQL cannot control rocket engines is technically true, ... I assure you I am not trolling anyone. ... > about relational and object oriented technology in general. ... More than that I do not understand what you want me to clarify. ...
    (comp.object)
  • Re: OO vs. RDB challenge
    ... >>just show that you have almost no knowledge at all about databases. ... > SQL code for power set challenge, ... To ask Costin would be trolling as he has many times explained... ... opposite's party argument ("ultimate language for parallel computing" ...
    (comp.object)
  • Re: Happy Java developer miserable with SQL
    ... As a developer with 8 years Java experience, a degree in Computer Science and a reasonable understanding of relational theory I find SQL blooming hard at times. ... There's at least two SQL news groups, ...
    (comp.lang.java.programmer)