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

bit setting

Is there an easy way to set a bit and clear a bit using a sub - something
like:

bitset(a,2) <-- sets 2nd bit in word
bitclr(a,5) <-- clears 5th bit in word
bittst( a,10) <-- test the 10th bit to see if it is set

I can create these myself, but wondered if there is already and easy way to
do this.

Thanks,

Tom
Nov 19 '05 #1
2 1164
Take a look at System.Collections.BitArray. You can reference and change
individual bits using an index easily.
"tshad" <tf*@dslextreme.com> wrote in message
news:#B*************@TK2MSFTNGP12.phx.gbl...
Is there an easy way to set a bit and clear a bit using a sub - something
like:

bitset(a,2) <-- sets 2nd bit in word
bitclr(a,5) <-- clears 5th bit in word
bittst( a,10) <-- test the 10th bit to see if it is set

I can create these myself, but wondered if there is already and easy way to do this.

Thanks,

Tom

Nov 19 '05 #2
"MWells" <outbound__at_sygnal.com> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Take a look at System.Collections.BitArray. You can reference and change
individual bits using an index easily.
What I am trying to do is take an integer (that will allow me up to 32
values) and set bits for selections that are made where the selections can
be one selection or multiple selections.

For example, I have 20 possible selections and the user can pick any
combination of choices (1, 4, 5, 12, 17 and 19) could be chosen. I would
then store this word into my database and later can tell which choices were
made.

Why would it be easier to use the System.Collections.BitArray than just to
"and", "or" and "xor" the values?

You still need to do all the same with the bitarrays. But you need to
create bitarray and load it to work with it.

Thanks,

Tom

"tshad" <tf*@dslextreme.com> wrote in message
news:#B*************@TK2MSFTNGP12.phx.gbl...
Is there an easy way to set a bit and clear a bit using a sub - something
like:

bitset(a,2) <-- sets 2nd bit in word
bitclr(a,5) <-- clears 5th bit in word
bittst( a,10) <-- test the 10th bit to see if it is set

I can create these myself, but wondered if there is already and easy way

to
do this.

Thanks,

Tom


Nov 19 '05 #3

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

Similar topics

6
by: Niyazi | last post by:
Hi, We have and IBM AS400 and I belive the reional setting is Turkish. The IBM Client-Access for Windows that install in our PC (WIN XP SP2) set to Turkish characters. Now my PC has English...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
0
by: Shravan | last post by:
Hi, I have a Windows Forms Custom DataGrid, which is put in a usercontrol, which on setting DataSource is setting focus to grid. The call stack for setting the focus is as follows. This is not...
2
by: junlia | last post by:
Hi All, I am working on a project that acts as a bridge. It does some checking with post xml data, and then redirects the request to an appropriate page. However, we find that depends on the...
1
by: Dachshund Digital | last post by:
I know there must be a way to do this... in .NET 2.0? I have a situation where I know the name of the setting, and want to pass it into a function, and set or get the corresponding setting. ...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
7
by: Ronald S. Cook | last post by:
In a .NET Windows app, if I set somehting like the title of the form to "MyApp" at run-time, will that make the app run slightly slower than if I had set the title at design-time? Thanks, Ron
6
by: metaperl | last post by:
I would like to check the setting of this variable in our MS-SQL 2000 database. Also, is there info on what the default value of this variable is?
8
by: Andrus | last post by:
..NET 2 Winforms application. How to create new setting and set it default value in userSettings section of app.config file or overwrite existing setting value ? I found code below in this list...
7
by: PetterL | last post by:
I have a setting called My.settings.firstrun set to True, set in the setting manager. When i read this in the first form form_Load in a IF sentence it always come out as false. I have tried to...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.