Pergunta de entrevista da empresa Valeo

Write a code that would add the number of ones in a byte.

Respostas da entrevista

Sigiloso

27 de jan. de 2017

#include unsigned char AddByteOnes(unsigned char byte); int main() { printf("%d\n", AddByteOnes(137)); return 0; } unsigned char AddByteOnes(unsigned char byte) { signed char loopCounter, sum = 0; for(loopCounter = 0; loopCounter > loopCounter; return (sum); }

Sigiloso

4 de jun. de 2017

int main() { char x = 26; int mask = 0x80; int sum=0; for(mask; mask!=0; mask>>=1){ if (mask&x){sum++;} } printf(" %d", sum); return 0; }