+4

# BCD-BINARY-SUMMIT//DAILY-DOSE//upto max limit (input)

bcd of a decimal no.(Binary-Coded-Decimal) eg: 167 bcd eqivalent-> 0001 0110 0111 binary eqivalent-> 10100111 TASK--> if number of 1's in binary is equal to number of 1's in bcd ''upto that length''of binary (from right to left) print the number, print bcd eqiv, print binary eqiv.. eg: 18---bcd 00011000 ( two 1's) 18--binary 10010 ( two 1's) eg: 179---bcd 0001 01111001 ( five 1's) 179--binary 10110011 (five 1's) # REMEMBER...UPTO BINARY LENGTH

8/24/2017 6:49:30 PM

sayan chandra

+10

179---bcd 0001 0111 1001 ( six 1's) 179--binary 10110011 (five 1's)

+9

Here's mine📝 https://code.sololearn.com/caqALbNPAJlk/?ref=app

+4

this is my code in Python.. It checks every number from 10 to the given input (the numbers from 1 to 9 obviously have this property because bin and bcd representations are equal) https://code.sololearn.com/cKajQ9vjyGg6/?ref=app

+4

SURVEY UPDATE---> @ vari93 @baptiste @ ysraelcon @sam0delk1n @prudhbi raju did everything perfect...with explaination. @seung @m abrate also as i wanted but try doing your function.. not predefined..but its ok

+3

mine https://code.sololearn.com/WdOjtYzkfhD9/?ref=app still thursday on here :) note: I think 179 isn't, ah, depending of the binary's length it is, I got it, fixed 👌

+3

Here's my C# implementation ✌ LINQ One-Liner〰 strNumBinary.Count(c => c == '1') == strNumTrimmedBCD.Count(c => c == '1') Unfortunately my program hit the limit of 300+ as it's a naive approach without optimization. I'll try to improve it when got time later. Enjoy! https://code.sololearn.com/ciI5ixbJDa2K/?ref=app

+3

I did not had the time to do it earlier ... My input starts at 10 and not 1 as numbers from 1 to 9 will always be printed, they have no interest edit : work with the binary length rule now https://code.sololearn.com/cG5tF5JqdAX7/?ref=app

+3

predefined? do you mean avoid format() and bin()?

+3

rewrote without bin(), format(), join(), range()

+2

numbers start from 0 to inputs ? from 9 to max of the data type ? (like unsigned)

+2

> eg: 167 > bcd eqivalent-> 0001 0110 0111 > binary eqivalent-> 1000111 Something wrong with your binary equivalent. 1000111b = 71d 167d = 10100111b

+2

dec bcd bin / only count 1s in bcd up to len(bin) https://code.sololearn.com/cNPveOvum2ad/?ref=app

+2

In the example of 179, bin has 8 digits '1011 0011'. And sayan only counts 1s in the last 8 digits of bcd '0111 1001', ignoring the first 4 digits '0001'. At least, that is how I understood and programmed my code.

+2

I guess "upto max limit (input)" in the title means all numbers from 1 to input

+2

https://code.sololearn.com/c9wAv9DRPSUn/#cpp @sayan, now it works on all numbers in range.

+1

This sounds fun, I'll work on it when I get out of class

+1

https://code.sololearn.com/c9wAv9DRPSUn/#cpp

+1

Alright, here you go lol. Finally got it to work, I was originally doing comparisons with literal binary representations in bcd, I wasn't adding 0s. Thank you Seung Moo. https://code.sololearn.com/ciL9PO3acX9t/?ref=app

+1

I think only one number needs print out, not all from 1 to N, see the first post.

+1

https://code.sololearn.com/csjC03FkilnP/?ref=app