Blog Home  Home Feed your aggregator (RSS 2.0)  
Software Code Help - How to match Two Hexadecimal value switch is On or OFF in C#
Blog
 
# Thursday, January 14, 2010

I have tested it using window application of C#,  In this we have two Hexadecimal value, And we check that the source value exists in our database or not.

        public Test()
        {
            InitializeComponent();

            //8 Byte Hexadecimal Value of source
            this.txtSource.Text = "0x00004000";

            //8 Byte Hexadecimal Value of DB
            this.txtDB.Text = "0xAF00D0b0";
        }

        private void button1_Click(object sender, EventArgs e)
        
        {
            //Convert the Hexadecimal value inot uint.
            uint i = GetHexValue(txtDB.Text.ToString());
            uint b = GetHexValue(txtSource.Text.ToString());
            
            txtResult.Text = (i & b) > 0 ? "Match" : "UnMatch";
        }

        //This is the function used for returning uint value from hexadecimal value.
        public uint GetHexValue(String text)
        {
            uint result = 0;
            String parseText = text;
            if (parseText.StartsWith("0x", true, CultureInfo.InvariantCulture))
            {
                parseText = text.Substring(2);
            }


            if (UInt32.TryParse(parseText, NumberStyles.AllowHexSpecifier, CultureInfo.InvariantCulture, out result) == false)
            {
                throw new ArgumentException("Text value must be a valid hexidecimal number" + text);
            }

            return result;
        }

 

Thursday, January 14, 2010 10:27:06 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]   C#  | 
Copyright © 2010 SoftwareCodeHelp. All rights reserved.
DasBlog 'Portal' theme by Johnny Hughes.
Pick a theme: