Hex to Long ich dreh durch


heyho folgendes,
hab einen string der eine hex-zahl enthält.
code: [select]
string zahl = string("0xf8");
den muss ich in meine variable reinbekommen, ich weiß aber nicht wie.
toint(); funktioniert nicht, da bekomm ich 0 raus, möchte aber eigentlich 0xf8 da drin stehen haben.
heeeelp!

code: [select]
const char source[] = "0xabcdef!";

void setup() {
  serial.begin(115200);
  char* behind;

  unsigned long result = strtoul(source, &behind, 16);

  serial.print(f("result 0x"));
  serial.print(result, hex);
  if (behind) {
    serial.print(f(", text after parsed: '"));
    serial.print(behind);
    serial.write('\'');
  }
  serial.println();
}
void loop() {}
code: [select]
result 0xabcdef, text after parsed: '!'

edit: funktioniert auch mit 0x prefix.


Arduino Forum > International > Deutsch (Moderator: uwefed) > Hex to Long ich dreh durch


arduino

Comments

Popular posts from this blog

Error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode - Raspberry Pi Forums

class MPU6050 has no member named begin

missing filename after '-o'