Skip to content

Commit

Permalink
itoa
Browse files Browse the repository at this point in the history
  • Loading branch information
xtruan committed Mar 3, 2023
1 parent ea660eb commit 804e0f1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
40 changes: 39 additions & 1 deletion helpers/flipbip_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
* SUCH DAMAGE.
*/
#include "flipbip_string.h"
#include <string.h>
// #include <string.h>
#include <ctype.h>
char *
flipbip_strtok(char *s, const char *delim)
{
Expand Down Expand Up @@ -75,4 +76,41 @@ flipbip_strtok_r(char *s, const char *delim, char **last)
} while (sc != 0);
}
/* NOTREACHED */
}
void
flipbip_strrev(unsigned char *str)
{
int i;
int j;
unsigned char a;
unsigned len = strlen((const char *)str);
for (i = 0, j = len - 1; i < j; i++, j--)
{
a = str[i];
str[i] = str[j];
str[j] = a;
}
}
int
flipbip_itoa(int num, unsigned char* str, int len, int base)
{
int sum = num;
int i = 0;
int digit;
if (len == 0)
return -1;
do
{
digit = sum % base;
if (digit < 0xA)
str[i++] = '0' + digit;
else
str[i++] = 'A' + digit - 0xA;
sum /= base;
}while (sum && (i < (len - 1)));
if (i == (len - 1) && sum)
return -1;
str[i] = '\0';
flipbip_strrev(str);
return 0;
}
2 changes: 2 additions & 0 deletions helpers/flipbip_string.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
char * flipbip_strtok(char *s, const char *delim);
char * flipbip_strtok_r(char *s, const char *delim, char **last);
void flipbip_strrev(unsigned char *str);
int flipbip_itoa(int num, unsigned char* str, int len, int base);
3 changes: 2 additions & 1 deletion views/flipbip_scene_1.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ static void flipbip_scene_1_model_init(FlipBipScene1Model* const model, const in

// Convert the seed to a hex string
for (size_t i = 0; i < 64; i++) {
sprintf(seed + (i * 2), "%.2x", seedbytes[i]);
flipbip_itoa(seedbytes[i], seed + (i * 2), 2, 16);
//sprintf(seed + (i * 2), "%.2x", seedbytes[i]);
}

// Split the seed into parts
Expand Down

0 comments on commit 804e0f1

Please sign in to comment.