Skip to main content
edited tags
Link
janos
  • 113.1k
  • 15
  • 154
  • 396
edited body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

decimal Decimal to binary algorithm

Is there a better way to code this specific algorithm using successively division through 2 which converts decimal numbers into binary numbers without calling a build inbuilt-in function?

print "Please enter a decimal number."
prompt = '>> '
dec_number = input(prompt)
dec_new = dec_number 
binstr = ''

'''dec2bin'''
while dec_new != 0:
  binstr += str(dec_new % 2)
  dec_new = dec_new // 2

print binstr[::-1]

decimal to binary algorithm

Is there a better way to code this specific algorithm using successively division through 2 which converts decimal numbers into binary numbers without calling a build in function?

print "Please enter a decimal number."
prompt = '>> '
dec_number = input(prompt)
dec_new = dec_number 
binstr = ''

'''dec2bin'''
while dec_new != 0:
  binstr += str(dec_new % 2)
  dec_new = dec_new // 2

print binstr[::-1]

Decimal to binary algorithm

Is there a better way to code this specific algorithm using successively division through 2 which converts decimal numbers into binary numbers without calling a built-in function?

print "Please enter a decimal number."
prompt = '>> '
dec_number = input(prompt)
dec_new = dec_number 
binstr = ''

'''dec2bin'''
while dec_new != 0:
  binstr += str(dec_new % 2)
  dec_new = dec_new // 2

print binstr[::-1]
Tweeted twitter.com/StackCodeReview/status/751054661487132672
edited tags
Link
Peilonrayz
  • 44.6k
  • 7
  • 80
  • 158
Loading
Source Link
間澤東雲
  • 233
  • 1
  • 2
  • 8
Loading