Browse Source

expanded binaryStrLen to determine length in case input is negative

remotes/origin/conversionOfNumbers
Laurin 11 months ago
parent
commit
fb4ad3c51b
  1. 8
      src/conversionOfNumbers/conversionOfNumbers.c

8
src/conversionOfNumbers/conversionOfNumbers.c

@ -5,11 +5,15 @@
#include "conversionOfNumbers.h" #include "conversionOfNumbers.h"
int binaryStrLen(int input){ int binaryStrLen(int input){
int length;
int length = 0;
if (input == 0) return 1; if (input == 0) return 1;
if (input < 0){
input *= -1;
length += 1;
}
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;
} }
} }

Loading…
Cancel
Save