473,326 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Extracting days of the week from int/binary

Hello All,

I'm writing an app to track file transfer activity.

I have this enum to represent days of the week:

Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
Sunday = 7

If a file should be transferred on a Monday and Friday, I add 1 to 5
and store 6.
How do I go back the way ?
e.g. I have a value of 6, how to get Monday and Friday ?

Pointers appreciated!
Regards
hharry

Sep 19 '07 #1
3 6390
You need to use bitwise values, i.e.

[Flags]
public enum Days {
None = 0,
Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8,
Friday = 16, Saturday = 32, Sunday = 64
}

Then "Monday and Friday" (in English) is Days.Monday | Days.Friday

To convert as a number, just cast:
int value = (int) days;
Days days = (Days) value;

To check for individual days:
if((days & Days.Tuesday) == Days.Tuesday)

Marc
Sep 19 '07 #2
You have to make the values assigned to particular days subsequent powers of 2
You can then put the [Flags] attribute on the enum:

[Flags]
enum DaysOfWeek {
Monday = 1,
Tuesday = 2,
Wednesday = 4,
Thursday = 8,
Friday = 16,
Saturday = 32,
Sunday = 64
}
Then you can do sth like this:
DaysOfWeek dd = DaysOfWeek.Monday | DaysOfWeek.Friday;

You can also check if a given value "contains" Monday in it:

if ((dd & DaysOfWeek.Monday) == DaysOfWeek.Monday) { // do sth }
Hope this helps,

_____________
Adam Bieganski
http://godevelop.blogspot.com
"hharry" wrote:
Hello All,

I'm writing an app to track file transfer activity.

I have this enum to represent days of the week:

Monday = 1
Tuesday = 2
Wednesday = 3
Thursday = 4
Friday = 5
Saturday = 6
Sunday = 7

If a file should be transferred on a Monday and Friday, I add 1 to 5
and store 6.
How do I go back the way ?
e.g. I have a value of 6, how to get Monday and Friday ?

Pointers appreciated!
Regards
hharry

Sep 19 '07 #3
all set. thx!

Sep 19 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
14
by: deko | last post by:
This runs, but does not narrow to current week. suggestions appreciated! SELECT lngEid, dtmApptDate, Subject, Appt_ID FROM qry002 WHERE (dtmApptDate BETWEEN DateAdd("d",-weekday()+2,) And...
10
by: Ty Smith via AccessMonster.com | last post by:
I noticed that the week numbers in Stephan Leban's MonthCalendar are not consistent with Microsoft Outlook (they are shifted one week forward). Is there any way I can sync these two up by changing...
2
by: deko | last post by:
I'm wondering if anyone has come across something like this before and could offer some suggestions. I need to extract all the Single values packed in a Long Binary field (4k chunks) and then...
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
2
by: tech101 | last post by:
Can I get the master (or slaves) to automatically remove the binary logs once they are processed by all slaves? It says in the mysql manual : If you are using replication, you should not delete...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.