1

First of all I'm sorry for the confusing title. I'm reading Adobe's specs of SWF and I saw a statement I'm not really sure how to code.

A one-byte version number follows the signature. The version number is not an ASCII character, but an 8-bit number. For example, for SWF 4, the version byte is 0x04, not the ASCII character “4” (0x34).

This effectively means that 0x20 is not a space, but actually the number 20.

Now, let's say I have this:

unsigned char c[1] = { 0x20 };

How would I get an integer with the value 20 out of c?

EDIT:

It turns out that not what I'm looking for. The byte with the version actually follows this scheme: Chart of SWF versions to Flash versions

Community
  • 1
  • 1
alexandernst
  • 14,352
  • 22
  • 97
  • 197

1 Answers1

1

Try this

char string[16];
int  value;
unsigned char c[1] = { 0x20 };

snprintf(string, sizeof(string), "%x", c[0]);
value = strtol(string, NULL, 10);

this will work as long as the hex representation of the number has a textual decimal equivalent, i.e. it wont work for 0xA0 for example.

Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • 2
    That will reinterpret a byte of what we used to call BCD as a decimal number (although it's clunky: you could just do `c[0] - 6*(c[0]>>4)`), but it seems highly unlikely that it what is really required here. – rici Jan 26 '15 at 00:41