It's a string rather than a integer because substr returns a strings, not integers.
You say Perl is typeless when the whole issue you're having is that you think that substr returns a value of a different type than it does.
You seem to claim your approach would work in C, but it wouldn't.
Output:#include <stdio.h> #include <stdlib.h> #include <string.h> char* substr(const char* src, size_t start, size_t len) { while (start && *src) { ++start; ++src; } char* dst = malloc(len+1); if (!dst) return NULL; dst[len] = 0; return strncpy(dst, src, len); } int main() { const char* s = "\x90"; char* first = substr(s, 0, 1); printf("%02X\n", first); free(first); return 0; }
$ gcc -Wall -Wextra -pedantic -std=c99 a.c -o a && a a.c: In function ‘main’: a.c:22:4: warning: format ‘%X’ expects argument of type ‘unsigned int’ +, but argument 2 has type ‘char *’ [-Wformat=] printf("%02X\n", first); ^ 1E25970
You need to do something to extract the number from the string: *first (C) or ord($first) (Perl).
In reply to Re^5: I've muddled my bit and byte formats.
by ikegami
in thread I've muddled my bit and byte formats.
by murrayn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |