Browse Source

added function to determine binary string length

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
08f6485826
  1. 14
      src/conversionOfNumbers/conversionOfNumbers.c

14
src/conversionOfNumbers/conversionOfNumbers.c

@ -1,5 +1,19 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h>
#include "conversionOfNumbers.h"
int binaryStrLen(int input){
int length;
for(int x = 0; x < input; x++){
if(pow(2,x) >= input + 1){
length = x;
break;
}
}
return length;
}
char* convertIntToBinaryStr(int input){ char* convertIntToBinaryStr(int input){
if(input > 3 || input < 0) return NULL; if(input > 3 || input < 0) return NULL;

Loading…
Cancel
Save