A series of text and numeric utilities useful for many purposes.
More...
Go to the source code of this file.
|
void | appendChar (char *str, char val, int len) |
|
void | ltoaClrBuff (char *str, long val, uint8_t dp, char padChar, int len) |
|
void | fastltoa_mv (char *str, long val, long divisor, char padChar, int len) |
|
void | fastltoa (char *str, long val, uint8_t dp, char padChar, int len) |
|
void | fastftoa (char *sz, float fl, int dp, int strSize) |
|
long | dpToDivisor (int dp) |
|
long | valueToSignificantPlaces (unsigned long value, bool negative) |
|
char | hexChar (uint8_t val) |
|
uint8_t | hexValueOf (char val) |
|
void | intToHexString (char *buffer, size_t bufferSize, unsigned int input, int digits, bool with0x) |
|
float | tcFltAbs (float f1) |
|
A series of text and numeric utilities useful for many purposes.
◆ appendChar()
void appendChar |
( |
char * |
str, |
|
|
char |
val, |
|
|
int |
len |
|
) |
| |
appends a character at the end of the string, if there is space according to len
◆ ltoaClrBuff()
void ltoaClrBuff |
( |
char * |
str, |
|
|
long |
val, |
|
|
uint8_t |
dp, |
|
|
char |
padChar, |
|
|
int |
len |
|
) |
| |
A fast long to ascii function that more feature complete than the standard library. Supports zero padding and maximum number of decimal places. This version always starts at position 0 in the provided buffer and goes up to position len always leaving space for a terminator. The other two versions below support appending instead.
- Parameters
-
str | the buffer to be output to |
val | the value to be converted |
divisor | the power of 10 largest value (eg 10000, 1000000L etc) |
padChar | the character to pad with (or NOT_PADDED which is 0) |
len | the length of the buffer passed in, it will not be exceeded. |
◆ fastltoa_mv()
void fastltoa_mv |
( |
char * |
str, |
|
|
long |
val, |
|
|
long |
divisor, |
|
|
char |
padChar, |
|
|
int |
len |
|
) |
| |
A fast long to ascii function that more feature complete than the standard library. Supports zero padding and the largest actual value to use normally a power of 10. Absolute largest value displayable is 1000000000 - 1. NOTE that this function will append at the end of the current string. Use ltoaClrBuff to start at position 0. This call will not exceed the length provided and will properly terminate the string.
- Parameters
-
str | the buffer to be appended to |
val | the value to be converted |
divisor | the power of 10 largest value (eg 10000, 1000000L etc) |
padChar | the character to pad with (or NOT_PADDED which is 0) |
len | the length of the buffer passed in, it will not be exceeded. |
◆ fastltoa()
void fastltoa |
( |
char * |
str, |
|
|
long |
val, |
|
|
uint8_t |
dp, |
|
|
char |
padChar, |
|
|
int |
len |
|
) |
| |
A fast long to ascii function that more feature complete than the standard library. Supports zero padding and the number of decimal places to use. Maximum number of decimal places is 9. NOTE that this function will append at the end of the current string and will not exceed the length provided, it will also properly terminate the string. Use ltoaClrBuff to start at position 0 in the buffer.
- Parameters
-
str | the buffer to be appended to |
val | the value to be converted |
dp | the number of decimal places allowed |
padChar | the character to pad with (or NOT_PADDED which is 0) |
len | the length of the buffer passed in, it will not be exceeded. |
◆ fastftoa()
void fastftoa |
( |
char * |
sz, |
|
|
float |
fl, |
|
|
int |
dp, |
|
|
int |
strSize |
|
) |
| |
A very simple floating point string function based on the fastltoa above. It can print floating point values up to 9 whole digits and 9 decimal places. Note this function appends the floating point value at the end of the string, to put the value at the beginning, ensure the string is zero length.
- Parameters
-
sz | the string to append to, |
fl | the float to convert |
dp | the numer of decimal places (max 9) |
strSize | the string maximum length (usually from sizeof) |
◆ dpToDivisor()
long dpToDivisor |
( |
int |
dp | ) |
|
converts decimal places into a suitable divisor, eg: 2 -> 100, 4 -> 10000
◆ valueToSignificantPlaces()
long valueToSignificantPlaces |
( |
unsigned long |
value, |
|
|
bool |
negative |
|
) |
| |
Indicates how many integers are needed to represent the value and negative flag if provided
- Parameters
-
value | the value to represent as unsigned. |
negative | if the value is negative |
- Returns
- the number of characters including the sign needed
◆ hexChar()
char hexChar |
( |
uint8_t |
val | ) |
|
Get the hex equivalent of a single digit, input must be between 0 and 15
- Parameters
-
val | the input unsigned integer between 0 and 15 |
- Returns
- a hex character from 0..F
◆ hexValueOf()
uint8_t hexValueOf |
( |
char |
val | ) |
|
Get the integer representation of a hex digit, between 0..F
- Parameters
-
- Returns
- the numeric representation.
◆ intToHexString()
void intToHexString |
( |
char * |
buffer, |
|
|
size_t |
bufferSize, |
|
|
unsigned int |
input, |
|
|
int |
digits, |
|
|
bool |
with0x |
|
) |
| |
Get the hex string for a number to a given number of fixed places, EG 4 digits. You can optionally include the '0x' at the beginning.
- Parameters
-
buffer | the buffer to copy into |
bufferSize | the size of the buffer |
input | the input number |
digits | the number of FIXED digits |
with0x | if 0x should be included at the beginning |
◆ tcFltAbs()
float tcFltAbs |
( |
float |
f1 | ) |
|
|
inline |
Ensure that a float is always positive.
- Parameters
-
f1 | the float that could be positive or negative |
- Returns
- the positive version of the float.