C# RegEx - FlagSet check in integer

G

Guest

Is it possible to find if lower 1st bit and 2nd bit in an 32-bit integer is set using regular expression in C#

Example

1. Input Strings - 0, 1, 2 Result - Fai
2. Input Strings - 3, 7, Result - Fail
 
J

Justin Rogers

AFAIK regular expressions don't have the ability to crack integers into
constituent components.
In other words there is no matching group that lets you specify bits, only
matching groups that let
you specify certain digits or strings of digits. Digits are represented as
character groups even, so
really you can only specify a string of characters that has the same matching
group as the characters
that represent numbers.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

CSharp said:
Is it possible to find if lower 1st bit and 2nd bit in an 32-bit integer is
set using regular expression in C# ?
 
T

Troy Jezeski

I don't know the specifics of your need, but it would probably be easier to
do this check with an AND bit mask.

For example:
// Check the lower 2 bits
if((((i & 0x00000003) > 0) && (i & 0x00000003) < 4))
{
MessageBox.Show("One or both of the lower 2 bits is set");
}// where i is a System.Int32



CSharp said:
Is it possible to find if lower 1st bit and 2nd bit in an 32-bit integer
is set using regular expression in C# ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top