Browse Source

added case in binaryStrLen for input 0 length is 1

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
e504c53d9f
  1. 6
      src/conversionOfNumbers/conversionOfNumbers.c

6
src/conversionOfNumbers/conversionOfNumbers.c

@ -6,13 +6,17 @@
int binaryStrLen(int input){ int binaryStrLen(int input){
int length; int length;
if(input > 0){
for(int x = 0; x < input; x++){ for(int x = 0; x < input; x++){
if(pow(2,x) >= input + 1){ if(pow(2,x) >= input + 1){
length = x; length = x;
break; break;
} }
} }
return length;
}else if(input == 0){
length = 1;
}
return length;
} }
char* convertIntToBinaryStr(int input){ char* convertIntToBinaryStr(int input){

Loading…
Cancel
Save