Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
When I output the individual hex values of this file which contains:
81 a8 90 47 48 00 00 00 48 00 00 00 0aI get the following:
ffffff81
ffffffa8
ffffff90
47 - (date back to front)
48 - (stock level)
00
00
00
48 - (average)
00
00
00
0a - (end of line)The prefixed "ffffff" values I have to remove before running my HexToDec function.
I get my expected values (contains, date, stock level and average) but why does this printf statement show values such as ffffff81, and ffffffa8 but are invisible in the file contents?
printf("%.2x\n",((char *)buffer)[i]);
This was previously loaded into a buffer char variable by reading the binary file from start to finish.
Thanks for your help
Andrew

This seems to have solved the problem:
printf("%.2x\n",((unsigned char *)buffer[i]);I then store all these hex values as strings and convert to decimal values.
If I use (unsigned int *), this works for the first line but I get unwanted values because line feed 0a runs into the date on the next line.
e.g (2 line file)
81 a8 90 47 48 00 00 00 48 00 00 00 0a 02 85 94
47 5c 00 00 00 a5 00 00 00 0aThe second date becomes as unsigned int 9485020a. This should be 47948502.
Therefore I prefer the unsigned char method so I can treat each individual hex value and store in overall date string, stock level and average.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |