473,387 Members | 1,440 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,387 software developers and data experts.

Bitwise operations

Gang,

I always get confused when it comes to 1's and 0's. I would like to perform
a bitwise operation on a value based on checked boxes.

Am I doing this right?
assuming TurmsRemote.Weekdays has values of

Monday =2
Tuesday =4
Wednesday =8
Thursday = 16
Friday =32
Saturday = 64
Sunday = 128
Sub Monday_Click(Sender, E)
dim chkbox as checkbox = ctype(sender, checkbox)

If chkbox.Checked Then
If Not Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays And TurmsRemote.Weekdays.Monday
End If
Else
If Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays - TurmsRemote.Weekdays.Monday
End If
End If

End Sub
Jan 20 '06 #1
4 1842
AMDRIT,

Why would you use it, it is in my opinion a little bit from the time that a
computer had 32K internal memory. (Therefore not so based on the Visual
Basic as you use).

It makes your program not better readable/maintanable while there is a nice
date class which has a method for weekdays for you.

http://msdn2.microsoft.com/en-us/library/t8dc1aee.aspx

Just my thought,

Cor
Jan 20 '06 #2
You could actually simplify your code a bit - the inner If statements
probably cause more processing than just doing the logical calculation:

Sub SwitchBit(ByRef checked As Boolean, ByRef weekday As
TurmsRemote.Weekdays)
If checked = True Then
Me.WeeklyDays = Me.WeeklyDays And weekday
Else
Me.WeeklyDays = Me.WeeklyDays And Not weekday
End If
End Sub

I'm sure you can figure out how to call it! Cuts down on copy&paste repeated
code this way.

If you're doing a lot of manipulation like this, drawing out a few logic
tables on paper is often quite helpful.

Hope it helps,

Jevon

"AMDRIT" <am****@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP12.phx.gbl...
Gang,

I always get confused when it comes to 1's and 0's. I would like to
perform a bitwise operation on a value based on checked boxes.

Am I doing this right?
assuming TurmsRemote.Weekdays has values of

Monday =2
Tuesday =4
Wednesday =8
Thursday = 16
Friday =32
Saturday = 64
Sunday = 128
Sub Monday_Click(Sender, E)
dim chkbox as checkbox = ctype(sender, checkbox)

If chkbox.Checked Then
If Not Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays And TurmsRemote.Weekdays.Monday
End If
Else
If Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays - TurmsRemote.Weekdays.Monday
End If
End If

End Sub

Jan 20 '06 #3
I appreciate your thoughts. I was attempting to minimize the number of
columns on a table. Rather than having 7 bit columns, I would have 1 column
to represent the same data. I am creating a scheduler that may execute jobs
on a daily basis (i.e 12 AM every Mon, Tues, Thur, Friday)

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
AMDRIT,

Why would you use it, it is in my opinion a little bit from the time that
a computer had 32K internal memory. (Therefore not so based on the Visual
Basic as you use).

It makes your program not better readable/maintanable while there is a
nice date class which has a method for weekdays for you.

http://msdn2.microsoft.com/en-us/library/t8dc1aee.aspx

Just my thought,

Cor

Jan 20 '06 #4
I understand better what it was that I was asking.

I wanted to have a value "x" represent the any or all of the values of a
list of values. To do so, I had wanted to perform bitwise operations to add
or remove values from "x". I have determined that I need to use the
operators ("Or" and "And Not") to add or remove values from "x"

Taking from Jevon's code reduction suggestion here is the resulting code:
(Jevon, I changed the byref's to byval's; was their a reason to use byref?)
Private Sub SwitchBit(ByVal checked As Boolean, ByVal weekday As
TurmsRemote.Weekdays)

If checked = True Then
Me.WeeklyDays = Me.WeeklyDays Or CType(weekday, Byte)
Else
Me.WeeklyDays = Me.WeeklyDays And Not CType(weekday, Byte)
End If

End Sub
This seems to solve all of the operations that I need. Unless anyone has
more to add, I will commit this to the ol' noggin for later use.
Thanks gang.

"AMDRIT" <am****@hotmail.com> wrote in message
news:e9*************@TK2MSFTNGP12.phx.gbl...
Gang,

I always get confused when it comes to 1's and 0's. I would like to
perform a bitwise operation on a value based on checked boxes.

Am I doing this right?
assuming TurmsRemote.Weekdays has values of

Monday =2
Tuesday =4
Wednesday =8
Thursday = 16
Friday =32
Saturday = 64
Sunday = 128
Sub Monday_Click(Sender, E)
dim chkbox as checkbox = ctype(sender, checkbox)

If chkbox.Checked Then
If Not Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays And TurmsRemote.Weekdays.Monday
End If
Else
If Me.WeeklyDays And TurmsRemote.Weekdays.Monday Then
Me.WeeklyDays = Me.WeeklyDays - TurmsRemote.Weekdays.Monday
End If
End If

End Sub

Jan 20 '06 #5

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

Similar topics

11
by: Randell D. | last post by:
Why would one use bitwise operators? I can program in various languages in some shape or form (C++, PHP, some scripting) and I've heard/seen bitwise operators before, but never understood why...
6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
10
by: Emilio | last post by:
Do I use 'or' for bitwise operations where in c# I use | ?
3
by: shdwsclan | last post by:
I am native to various languages but bitwise operators just kill me. I see how much I take object oriented languages for granted. I like all the other c derivitives but ANSI C is making me loose my...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
8
by: Daniel Gutson | last post by:
Hi, I just wanted to share another library for doing type-safe bitwise operations in C++: http://bitwise-enum.googlecode.com I found it useful, so hopefully it'll be for somebody else as well....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.