In CubeIDE, Can scanf() read an 8 character hexadecimal value, or is this a known bug?
When I attempt to read an 8 character hexadecimal value with sscanf(), I get 0x7FFFFFFF for all values over "80000000". It's as if sscanf() is confusing signed and unsigned numbers. If I read the 8 characters as two sets of 4, there is no problem (this is my workaround). If I try this scaled down to 16 bits, there is no problem. If I put this same code in visual studio (with sscanf deprecation disabled), there is no problem. I'm just using "include <stdio.h>" to get sscanf() as it ships with CubeIDE.
The attached code snippet is for illustration. It only take lines 13-15 or 19-21 to recreate the problem.
int size32=sizeof(unsigned int); //just to verify data sizes
int size16=sizeof(unsigned short); //just to verify data sizes
//need to read in 8 characters as a 32 bit hex value
char str1[]="12345678";
unsigned int val1;
int res1=sscanf(str1,"%8X",&val1);
char str2[]="7F123456";
unsigned int val2;
int res2=sscanf(str2,"%8X",&val2);
char str3[]="80123456";
unsigned int val3;
int res3=sscanf(str3,"%8X",&val3);
//val3 should be 0x80123456, but sscanf returns 0x7FFFFFFF
//THIS is the issue of this post
char str4[]="FEDCBA98";
unsigned int val4;
int res4=sscanf(str4,"%8X",&val4);
//val4 should be 0xFEDCBA98, but sscanf returns 0x7FFFFFFF
//THIS is the issue of this post
unsigned int val5,val6;
int res5=sscanf(str4,"%4X%4X",&val5,&val6);
unsigned int val7=(val5<<16)+val6;
//scanned as separate 4+4 chars instead of 8, no problem
//trying the same thing scaled down to 16 bits
char str10[]="1234";
unsigned short val10;
int res10=sscanf(str10,"%4hX",&val10);
char str11[]="FEDC";
unsigned short val11;
int res11=sscanf(str11,"%4hX",&val11);
