C# RegEx - FlagSet check in integer

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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# ?
 
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# ?
 
Back
Top