[Prev] [Next] [Top] [Bottom] [Contents] (9 out of 193)

SaAsciiToHex

Converts a string of ascii characters to binary data.

Synopsis

#include "WorkingDialog.h"

void *SaAsciiToHex(char *str, int *siz);

Arguments

str
A pointer to a Null terminated string to be converted to binary.
siz
A pointer to an integer which will return the size of the returned buffer. It is generally 1/2 the size of the character string passed in, unless an "0x" prepends the string and then it is (strlen -2)/2.

Return Values

A void pointer to a buffer containing the converted binary data, or NULL on failure. This buffer must be free'd to avoid memory leaks.

Description

SaAsciiToHex assumes that a string containing characters that represent binary data is provided.

A "0x" can be prepended to the input string if desired, but is not necessary.

Valid character values are `0' - `9' and `a', `b', `c', `d', `e', or `f' (case insensitive)

Failures occur if malloc fails or invalid characters are found.

Example

#include "WorkingDialog.h"
...
#define cbin "FF2C324EFF00"; /* could also be
		"0xFF2C324EFF00" */
	void *binary;				/* pointer for binary data */
	int size;					/* return size of buffer */
	if((binary = SaAsciiToHex(cbin, &size)) == NULL)
		return;
	write(file_descriptor, (char *)binary, size);
...

See Also


[Prev] [Next] [Top] [Bottom] [Contents] (9 out of 193)