1
0
mirror of https://git.code.sf.net/p/zint/code synced 2025-12-18 10:27:09 +00:00

Simplify conversion to binary with common function

No change to functionality
This commit is contained in:
Robin Stuart
2017-05-14 08:15:08 +01:00
parent 19ba8a34c4
commit 19c3755ed0
9 changed files with 321 additions and 733 deletions

View File

@@ -55,6 +55,25 @@ char itoc(const int source) {
}
}
/* Convert an integer value to a string representing its binary equivalent */
void bin_append(const int arg, const int length, char *binary) {
int i;
int start;
int posn = strlen(binary);
start = 0x01 << (length - 1);
for (i = 0; i < length; i++) {
binary[posn + i] = '0';
if (arg & (start >> i)) {
binary[posn + i] = '1';
}
}
binary[posn + length] = '\0';
return;
}
/* Converts lower case characters to upper case in a string source[] */
void to_upper(unsigned char source[]) {
size_t i, src_len = ustrlen(source);