void bitprint(int n)
{
for(int i = sizeof(n)*8-1; i >= 0; i --)//C99 standard for loop and comment.
printf("%d", (n&(1<<i))>>i);
}
//It's exactly not a one liner, but this prints out the integer in binary form. The parameter can be changed //to a long if you want.
int gcd(int p, int q)
{
for(int i = p < q?p:q; i > 0; i --)
if(!(p%i) && !(q%i))
return i;
return -1;
}
//This is not a one liner either, but I like it. It returns the greatest common denominator.
/**
* @description Finds the character in the string
* @param string to find in
* @param character to find
* @return the pointer to the character in string
*/
char *find_chr(char *input, char find)
{
while(*input != find&&*input++)
;
return input;
}
/**
* @description This splits the string at the inputted character
* @param original string
* @param pointer to lower half of the string
* @param pointer to other half of the string
* @param character to find and split at
* @return void
*/
void split(char *orig, char **p, char **s, char c)
{
char *temp = find_chr(orig, c);
char *pop = (char*)malloc(sizeof(char) * (temp - orig));
*p = pop;
while(orig != temp)
*pop++ = *orig++;
*s = ++temp;
}
/**
* @description This shifts every character over indicated number of times
* @param input string to be manipulated
* @param number of steps to shift over
* @return void
*/
void Caesar(char **input, int shift)
{
char *temp = (char*)malloc(sizeof(char)*strlen(*input));
for(int i = 0; i < strlen(*input); i ++){
if(isalpha(*(*input+i)))
*(temp+i) = (*(*input+i)+shift>122?(96+(shift-(122-tolower(*(*input+i))))):tolower(*(*input+i))+shift);
else
*(temp+i) = ' ';
}
*input = temp;
}
/**
* @description This reverses the Caesar algorithm
* @param input string to be manipulated
* @param number of steps to shift over
* @return void
*/
void deCaesar(char **input, int shift)
{
char *temp = (char*)malloc(sizeof(char)*strlen(*input));
for(int i = 0; i < strlen(*input); i ++){
if(isalpha(*(*input+i)))
*(temp+i) = (*(*input+i)-shift<97?(123-(shift-(tolower(*(*input+i))-97))):tolower(*(*input+i))-shift);
else
*(temp+i) = ' ';
}
*input = temp;
}