PDA

View Full Version : Solved: Is it possible to set a bit in a long integer ?



gmulhall
06-13-2007, 04:40 AM
Hi,

I have a need to set one or more bits in a long integer.

Each bit in the long represents assignment to one or more lists.

I'm actually updating a database in the Stock Trading Charting package Amibroker.

An example is provided in JScript - but I'd like to code in Excel VBA (my language of choice).

The example is below.

Stock.WatchListBits (long) - each bit 0..31 represents assignment to one of 32 watch lists to add a stock to nth watch list write (JScript example):
Stock.WatchListBits |= 1 << nth;

From Bullen/Bovey/Green I understand I need to use a Bitmask but I have no example. Did not find anything in Excel help either.

Is this do-able in Excel ? Does anyone have an example pls ?

Thanks as always,

Geoff

Bob Phillips
06-13-2007, 05:19 AM
You need to or it with 2 power of position



integer OR 2^0

integer OR 2^4

gmulhall
06-13-2007, 04:02 PM
Excellent. Thanks so much.

Always appreciate the fantastic assistance from everyone on this forum.

Geoff

:rotlaugh:

gmulhall
06-16-2007, 10:49 PM
Hi again,

Found the following very helpful on this subject

http://www.romanpress.com/Articles/Bitwise_R/Bitwise.htm

and

http://www.logicalexpressions.com/vbtip02.htm

The second is particularly relevant.

Geoff

Bob Phillips
06-17-2007, 01:42 AM
Aren't they the same article?

gmulhall
06-17-2007, 03:45 AM
Oops. Fixed now. :o: