System.Number.HexNumberToUInt32 C# (CSharp) Method

HexNumberToUInt32() private static method

private static HexNumberToUInt32 ( NumberBuffer &number, UInt32 &value ) : Boolean
number NumberBuffer
value UInt32
return Boolean
        private unsafe static Boolean HexNumberToUInt32(ref NumberBuffer number, ref UInt32 value) {

            Int32 i = number.scale;
            if (i > UInt32Precision || i < number.precision) { 
                return false;
            }
            Char* p = number.digits;
            BCLDebug.Assert(p != null, "");

            UInt32 n = 0;
            while (--i >= 0) {
                if (n > ((UInt32)0xFFFFFFFF / 16)) {
                    return false;
                }
                n *= 16;
                if (*p != '\0') {
                    UInt32 newN = n;
                    if (*p != '\0') {
                        if (*p >= '0' && *p <= '9') {
                            newN += (UInt32)(*p - '0');
                        }
                        else {
                            if (*p >= 'A' && *p <= 'F') {
                                newN += (UInt32)((*p - 'A') + 10);
                            }
                            else {
                                BCLDebug.Assert(*p >= 'a' && *p <= 'f', "");
                                newN += (UInt32)((*p - 'a') + 10);
                            }
                        }
                        p++;
                    }
                
                    // Detect an overflow here...
                    if (newN < n) { 
                        return false;
                    }
                    n = newN;
                }
            }
            value = n;
            return true;
        }

Usage Example

示例#1
0
        private static bool HexNumberToInt32(ref Number.NumberBuffer number, ref int value)
        {
            uint num1 = 0;
            int  num2 = Number.HexNumberToUInt32(ref number, ref num1) ? 1 : 0;

            value = (int)num1;
            return(num2 != 0);
        }
All Usage Examples Of System.Number::HexNumberToUInt32