카타 8급 Bin to Decimal

C[ | ]

unsigned bin_to_decimal(const char *bin) {
  return strtol(bin, 0, 2);
}
unsigned bin_to_decimal(const char *bin) {
  unsigned res = 0;
  while(*bin) {
    res = res*2 + *bin-'0';
    bin++;
  }
  return res;
}
unsigned bin_to_decimal(const char *bin) {
  unsigned res = 0;
  while(*bin) res = res*2 + *bin++ - '0';
  return res;
}
unsigned bin_to_decimal(const char *bin) {
  unsigned res = 0;
  while(*bin) {
    res <<= 1;
    res |= *bin=='1';
    bin++;
  }
  return res;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}