#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
FILE *FS;
FILE *LF;
unsigned int HexDec(char Hx[16])
{
unsigned int ret;
ret = (long int)strtol(Hx, NULL, 16);
return ret;
}
char DecHex(unsigned int Dec) //4 bytes
{
char ret[16];
sprintf(ret,"%08x", Dec);
return ret;
}
char BinHex(char Bin[16]) //4 Bytes
{
char ret[16];
sprintf(ret, "%02x%02x%02x%02x", (unsigned int) Bin[0] & 0xFF, (unsigned int) Bin[1] & 0xFF, (unsigned int) Bin[2] & 0xFF, (unsigned int) Bin[3] & 0xFF);
return ret;
}
void main()
{
char BIN[16] = "AA55";
char HEX[16] = BinHex(BIN);
unsigned int DEC = HexDec(HEX);
char DECHEX[16] = DecHex(DEC);
printf("Bin: %s\n\n", BIN);
printf("To Hex: %s\nTo Dec: %u\n\n Dec %u to Hex %s\n", HEX, DEC, DEC, DECHEX);
}
I am currently rewriting horrible looking test code and trying to get some functions to clean up, but I'm running into the issue where I must have arrays not pointers returned to be able to manipulate the data being processed.
?The end goal is to give me access to my custom File System threw linux terminal. Currently my first code works flawlessly, but the code is so hard to read and has the same segments over and over again (these segments are what I'm trying to get into functions).
The function DecHex is the main one I am worried about returning as an array because my code currently looks like:
//sprintf(hx,"%08x",(unsigned int) filesize); what is currently here
hx = DecHex(filesize);
printf("Hex value of Decimal value %ld is %s\n",filesize,hx);
sprintf (tmp, "%c%c", hx[6], hx[7]);
tmpb = strtol(tmp, NULL, 16);
printf("%s - %u\n", tmp, tmpb);
putc(tmpb, FS);
sprintf (tmp, "%c%c", hx[4], hx[5]);
tmpb = strtol(tmp, NULL, 16);
printf("%s - %u\n", tmp, tmpb);
putc(tmpb, FS);
sprintf (tmp, "%c%c", hx[2], hx[3]);
tmpb = strtol(tmp, NULL, 16);
printf("%s - %u\n", tmp, tmpb);
putc(tmpb, FS);
sprintf (tmp, "%c%c", hx[0], hx[1]);
tmpb = strtol(tmp, NULL, 16);
printf("%s - %u\n", tmp, tmpb);
putc(tmpb, FS);
And as I stated my old code is bad for the eyes (~900 lines of confusing), I am getting to that part but first I need this pointer array issue fixed.
If you need my old code for something let me know, otherwise it is best kept away from eyes lol.
Any help is appreciated, Thanks in advance B T Hoover