… | |
… | |
934 | =head3 HIGH LEVEL API |
934 | =head3 HIGH LEVEL API |
935 | |
935 | |
936 | The high level API consists of four functions, one each for C<int32_t>, |
936 | The high level API consists of four functions, one each for C<int32_t>, |
937 | C<uint32_t>, C<int64_t> and C<uint64_t>: |
937 | C<uint32_t>, C<int64_t> and C<uint64_t>: |
938 | |
938 | |
|
|
939 | Example: |
|
|
940 | |
|
|
941 | char buf[ECB_I2A_MAX_DIGITS + 1]; |
|
|
942 | char *end = ecb_i2a_i32 (buf, 17262); |
|
|
943 | *end = 0; |
|
|
944 | // buf now contains "17262" |
|
|
945 | |
939 | =over |
946 | =over |
940 | |
947 | |
941 | =item ECB_I2A_I32_DIGITS (=11) |
948 | =item ECB_I2A_I32_DIGITS (=11) |
942 | |
949 | |
943 | =item char *ecb_i2a_u32 (char *ptr, uint32_t value) |
950 | =item char *ecb_i2a_u32 (char *ptr, uint32_t value) |
… | |
… | |
983 | for "leading zeroes"), functions that generate up to N digits, skipping |
990 | for "leading zeroes"), functions that generate up to N digits, skipping |
984 | leading zeroes (C<_N>), and functions that can generate more digits, but |
991 | leading zeroes (C<_N>), and functions that can generate more digits, but |
985 | the leading digit has limited range (C<_xN>). |
992 | the leading digit has limited range (C<_xN>). |
986 | |
993 | |
987 | None of the functions deal with negative numbera. |
994 | None of the functions deal with negative numbera. |
|
|
995 | |
|
|
996 | Example: convert an IP address in an u32 into dotted-quad: |
|
|
997 | |
|
|
998 | uint32_t ip = 0x0a000164; // 10.0.1.100 |
|
|
999 | char ips[3 * 4 + 3 + 1]; |
|
|
1000 | char *ptr = ips; |
|
|
1001 | ptr = ecb_i2a_3 (ptr, ip >> 24 ); *ptr++ = '.'; |
|
|
1002 | ptr = ecb_i2a_3 (ptr, (ip >> 16) & 0xff); *ptr++ = '.'; |
|
|
1003 | ptr = ecb_i2a_3 (ptr, (ip >> 8) & 0xff); *ptr++ = '.'; |
|
|
1004 | ptr = ecb_i2a_3 (ptr, ip & 0xff); *ptr++ = 0; |
|
|
1005 | printf ("ip: %s\n", ips); // prints "ip: 10.0.1.100" |
988 | |
1006 | |
989 | =over |
1007 | =over |
990 | |
1008 | |
991 | =item char *ecb_i2a_02 (char *ptr, uint32_t value) // 32 bit |
1009 | =item char *ecb_i2a_02 (char *ptr, uint32_t value) // 32 bit |
992 | |
1010 | |