#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Bit Masking

Is bit masking restricted to long or integer type only?

I created a function that determines when events can happen on
several different days based on what day of the week a month begins
and how many days are in the month.
My idea was to assign each date to a bit and when a date was passed to
the function it would use bit masking to return whether the date was
one of the selected dates.
It works until a month with 31 days because 2^31 is larger than a
long.
I tried to use double type and got the overflow error.
I tried to use the CDec conversion but nothing seems to work.

I've searched Google and Deja and I not found a solution
Thanks for any advice
Merlyn

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Bit Masking

A clarification
If just the 31st was chosen the it works ok. It is when 2^31 plus any
other day is added that it exceeds the long data type.
On Thu, 04 Mar 2004 18:53:19 -0700, Merlyn Knight
wrote:

Is bit masking restricted to long or integer type only?

I created a function that determines when events can happen on
several different days based on what day of the week a month begins
and how many days are in the month.
My idea was to assign each date to a bit and when a date was passed to
the function it would use bit masking to return whether the date was
one of the selected dates.
It works until a month with 31 days because 2^31 is larger than a
long.
I tried to use double type and got the overflow error.
I tried to use the CDec conversion but nothing seems to work.

I've searched Google and Deja and I not found a solution
Thanks for any advice
Merlyn


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default Bit Masking

You could use two longs and create your own bitset/clear/test functions.
As a quick example:

Sub test()
Dim HiLong As Long, LoLong As Long
BitSet HiLong, LoLong, 40

Debug.Print BitTest(HiLong, LoLong, 45)
Debug.Print BitTest(HiLong, LoLong, 40)
End Sub

Sub BitSet(HiLong As Long, LoLong As Long, BitNum As Long)
If BitNum = 0 And BitNum < 64 Then
If BitNum = 32 Then
HiLong = HiLong Or 2 ^ (BitNum - 32)
Else
LoLong = LoLong Or BitNum
End If
End If
End Sub

Function BitTest(HiLong As Long, LoLong As Long, BitNum As Long) As Boolean
If BitNum = 0 And BitNum < 64 Then
If BitNum = 32 Then
BitTest = (HiLong And 2 ^ (BitNum - 32))
Else
BitTest = (LoLong And BitNum)
End If
End If
End Function


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Merlyn Knight" wrote in message
...
A clarification
If just the 31st was chosen the it works ok. It is when 2^31 plus any
other day is added that it exceeds the long data type.
On Thu, 04 Mar 2004 18:53:19 -0700, Merlyn Knight
wrote:

Is bit masking restricted to long or integer type only?

I created a function that determines when events can happen on
several different days based on what day of the week a month begins
and how many days are in the month.
My idea was to assign each date to a bit and when a date was passed to
the function it would use bit masking to return whether the date was
one of the selected dates.
It works until a month with 31 days because 2^31 is larger than a
long.
I tried to use double type and got the overflow error.
I tried to use the CDec conversion but nothing seems to work.

I've searched Google and Deja and I not found a solution
Thanks for any advice
Merlyn




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
masking with symbol xxxx oldLearner57 Excel Discussion (Misc queries) 4 August 28th 08 01:53 PM
Masking out characters in a cell dnardi Excel Worksheet Functions 9 December 18th 07 08:04 PM
masking credit card info when worksheet is printed terwilli Excel Discussion (Misc queries) 2 January 17th 07 10:48 PM
Display masking goto_guy Excel Discussion (Misc queries) 2 March 30th 06 11:38 PM
Masking numbers RNeducator Excel Worksheet Functions 2 December 2nd 05 02:25 PM


All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"