Sha256: 65cf8b7de4adaf2f05d6fb5b43fd35713f76ce8b44250c9885363650df1d43d2

Contents?: true

Size: 334 Bytes

Versions: 311

Compression:

Stored size: 334 Bytes

Contents

#include "binary.h"
#include <string.h>

int convert(const char *input)
{
   size_t input_len = strlen(input);
   int result = 0;
   for (size_t i = 0; i < input_len; i++) {
      result <<= 1;
      if (input[i] == '1') {
         result |= 1;
      } else if (input[i] != '0') {
         return -1;
      }
   }
   return result;
}

Version data entries

311 entries across 311 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.179 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.178 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.177 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.176 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.175 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.174 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.173 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.172 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.171 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.170 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.169 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.167 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.166 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.165 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.164 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.163 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.162 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.161 tracks/c/exercises/binary/src/example.c
trackler-2.2.1.160 tracks/c/exercises/binary/src/example.c