+ 1

it's supposed to take a hexa decimal number turn it into binary and then print the 1's in the binary.the first i'm getting right

https://code.sololearn.com/cwLsR3xJXXs9/#c

24th May 2018, 6:35 PM
Tanvir Hasan
Tanvir Hasan - avatar
3 odpowiedzi
+ 1
if you want to take hexadecimal as a input from the user.. so used this scanf("%i",&a); %i take input as decimal number octal number and hexadecimal number ...... i hope this program will help you ti understand better https://code.sololearn.com/c2xHtxgkwBTQ/?ref=app
24th May 2018, 7:24 PM
Arun Tomar
Arun Tomar - avatar
+ 1
1. The gets function was removed in the C11 standard. 2. The entered string can be converted to a long value using strtol or strtoul so there is no need for your wierd switch case block. 3. A simple for loop can shift through the long value to determine the number of 1's and generate the binary string pattern at the same time." What did they replace the getter method with?
25th May 2018, 9:19 AM
Apple Blossom
Apple Blossom - avatar
0
not what i meant.you see the if you input 11 it gives me 0001001 (correct) and 5.but the 1's in binary are 2 but it gives me 5. check the editted code.
24th May 2018, 7:37 PM
Tanvir Hasan
Tanvir Hasan - avatar