--- cvsroot/libecb/ecb.pod 2021/06/22 00:01:15 1.90 +++ cvsroot/libecb/ecb.pod 2021/07/31 16:13:30 1.94 @@ -170,8 +170,8 @@ Evaluates to a true value (suitable for both preprocessor and C code testing) if 64 bit integer types on this architecture are evaluated -"natively", that is, with similar speeds as 32 bit integerss. While 64 bit -integer support is very common (and in fatc required by libecb), 32 bit +"natively", that is, with similar speeds as 32 bit integers. While 64 bit +integer support is very common (and in fact required by libecb), 32 bit cpus have to emulate operations on them, so you might want to avoid them. =item ECB_AMD64, ECB_AMD64_X32 @@ -733,7 +733,8 @@ These two families of functions return the value of C after rotating all the bits by C positions to the right (C) or left -(C). +(C). There are no restrictions on the value C, i.e. both +zero and values equal or larger than the word width work correctly. Current GCC/clang versions understand these functions and usually compile them to "optimal" code (e.g. a single C or a combination of C @@ -936,6 +937,13 @@ The high level API consists of four functions, one each for C, C, C and C: +Example: + + char buf[ECB_I2A_MAX_DIGITS + 1]; + char *end = ecb_i2a_i32 (buf, 17262); + *end = 0; + // buf now contains "17262" + =over =item ECB_I2A_I32_DIGITS (=11) @@ -945,7 +953,7 @@ Takes an C I and formats it as a decimal number starting at I, using at most C characters. Returns a pointer to just after the generated string, where you would normally put -the temrinating C<0> character. This function outputs the minimum number +the terminating C<0> character. This function outputs the minimum number of digits. =item ECB_I2A_U32_DIGITS (=10) @@ -975,8 +983,8 @@ =head3 LOW-LEVEL API The functions above use a number of low-level APIs which have some strict -limitaitons, but cna be used as building blocks (study of C -and related cunctions is recommended). +limitations, but can be used as building blocks (study of C +and related functions is recommended). There are three families of functions: functions that convert a number to a fixed number of digits with leading zeroes (C, C<0> @@ -984,7 +992,18 @@ leading zeroes (C<_N>), and functions that can generate more digits, but the leading digit has limited range (C<_xN>). -None of the functions deal with negative numbera. +None of the functions deal with negative numbers. + +Example: convert an IP address in an u32 into dotted-quad: + + uint32_t ip = 0x0a000164; // 10.0.1.100 + char ips[3 * 4 + 3 + 1]; + char *ptr = ips; + ptr = ecb_i2a_3 (ptr, ip >> 24 ); *ptr++ = '.'; + ptr = ecb_i2a_3 (ptr, (ip >> 16) & 0xff); *ptr++ = '.'; + ptr = ecb_i2a_3 (ptr, (ip >> 8) & 0xff); *ptr++ = '.'; + ptr = ecb_i2a_3 (ptr, ip & 0xff); *ptr++ = 0; + printf ("ip: %s\n", ips); // prints "ip: 10.0.1.100" =over @@ -1046,7 +1065,7 @@ 16 bit range) and C (a bit more than 31 bit range), respectively. -For example, the sigit part of a 32 bit signed integer just fits into the +For example, the digit part of a 32 bit signed integer just fits into the C range, so while C cannot convert a 10 digit number, it can convert all 32 bit signed numbers. Sadly, it's not good enough for 32 bit unsigned numbers.