Skip to content
Snippets Groups Projects
Commit f0faf2fa authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Get working version of mask and shift (only from base 10)

parent 46d1a118
No related merge requests found
File added
...@@ -23,24 +23,49 @@ char* MaskFromBaseTen(char * input, unsigned int base) { ...@@ -23,24 +23,49 @@ char* MaskFromBaseTen(char * input, unsigned int base) {
printf(" Starting MaskFromBaseTen \n"); printf(" Starting MaskFromBaseTen \n");
// Initialize Variables. // Initialize Variables.
int index; int index = 0;
int stringLength; int stringLength;
int x = atoi(input); unsigned int inputInt = atoi(input);
unsigned int remainderInt;
char outputString[32];
char tempString[32];
char* table = "0123456789ABCDEF"; char* table = "0123456789ABCDEF";
char* powerTable = "0011222233333334";
// Aquire char length of string and create buffer of appropriate size. // Pad first character or else output breaks due to sprintf formatting.
stringLength = (strlen(input) + 1); // (It tries to include the null characterString when I put in the first remainder).
char outputString[stringLength]; outputString[0] = 0;
index++;
// Do the really confusing 4 bit shift thingy. // While not 0, shift and mask appropriately.
// Start at a length in the array(aka buffer) which is the ending, while (inputInt != 0 ) {
// null-terminator character, then work backwards, shifting each // Use masking to find remainder value.
// bit over by 4 values? ...I think? ...or something?? remainderInt = (inputInt & (base - 1));
for (index = stringLength; index >=0; index--) { printf(" Debugging, Remainder: %u \n", remainderInt);
outputString[index] = table[x & 0xF]; // Mask here? ...am I masking for ending value? //outputString[index] = remainderInt;
x = x >> 4; sprintf(tempString, "%s%u", outputString, remainderInt);
printf(" Debugging, ShiftThing: %s \n", &outputString[0]); strncpy(outputString, tempString, 32);
// Use shifting to find next value.
inputInt = (inputInt >> (powerTable[base] - '0'));
printf(" Debugging, NextInputValue: %u \n", inputInt);
index++;
printf(" Debugging, OutputString: %s \n", outputString);
//printf(" Debugging, intString: %u \n", );
}
printf(" Debugging, PreSwap: %s \n", outputString);
// Create pointers and swap values.
char* strPointer1 = &outputString[1];
char* strPointer2 = &outputString[index - 2];
printf(" Debugging, pnt1: %s, pnt2: %s \n", strPointer1, strPointer2);
while (strPointer1 < strPointer2) {
SwapValues(strPointer1, strPointer2);
strPointer1++;
strPointer2--;
} }
printf(" Debugging, PostSwap: %s \n", outputString);
// Create buffer to return. // Create buffer to return.
char* buffer = malloc(strlen(outputString) + 1); char* buffer = malloc(strlen(outputString) + 1);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment