카타 8급 Convert to Binary

C[ | ]

unsigned long long to_binary(unsigned short num) {
  unsigned long long res = 0;
  unsigned long long pos = 1;
  while(num) {
    res += pos * (num%2);
    pos *= 10;
    num /= 2;
  }
  return res;
}
unsigned long long to_binary(unsigned short num) {
  unsigned long long res = 0;
  unsigned long long pos = 1;
  while(num) {
    res += pos * (num&1);
    pos *= 10;
    num >>= 1;
  }
  return res;
}
unsigned long long to_binary(unsigned short num) {
  unsigned long long pos, res = 0;
  for(pos=1; num>0; num>>=1, pos*=10) {
    if(num & 1) res += pos;
  }
  return res;
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}