how to cast an array of char into a single integer number?
- by SepiDev
Hi guys, i'm trying to read contents of PNG file.
As you may know, all data is written in a 4-byte manner in png files, both text and numbers. so if we have number 35234 it is save in this way:
[1000][1001][1010][0010].
but sometimes numbers are shorter, so the first bytes are zero, and when I read the array and cast it from char* to integer I get wrong number. for example [0000] [0000] [0001] [1011]
sometimes numbers are misinterpreted as negative numbers and simetimes as zero!
let me give you an intuitive example:
char s_num[4] = {120, 80, 40, 1};
int t_num = 0;
t_num = int(s_num); => 3215279148 ??????
the result should be 241 but the output is 3215279148?
I wish I could explain my problem well!
how can i cast such arrays into a single integer value?