From 55f8655316f59888bfa88409ac728c791613f13f Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 21 May 2023 12:38:47 -0400 Subject: [PATCH] cwNumericConvert.h : string_to_number() now recognizes hex numbers. --- cwNumericConvert.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cwNumericConvert.h b/cwNumericConvert.h index 5e4b022..ebc6d50 100644 --- a/cwNumericConvert.h +++ b/cwNumericConvert.h @@ -78,9 +78,14 @@ namespace cw valueRef = 0; // BUG BUG BUG why is this not an error ???? else { + int base = 10; errno = 0; - long v = strtol(s,nullptr,10); - if( v == 0 and errno != 0) + + if( strlen(s) >= 2 && s[0]=='0' && s[1]=='x' ) + base = 16; + + long v = strtol(s,nullptr,base); + if( v == 0 && errno != 0) return cwLogError(kOpFailRC,"String to number conversion failed on '%s'.", cwStringNullGuard(s)); return numeric_convert(v,valueRef); @@ -98,7 +103,7 @@ namespace cw { errno = 0; valueRef = strtod(s,nullptr); - if( valueRef == 0 and errno != 0) + if( valueRef == 0 && errno != 0) return cwLogError(kOpFailRC,"String to number conversion failed on '%s'.", cwStringNullGuard(s)); }