Quick actions

cmd+k|ctrl+k

Navigation

Languages

ex31_pyfml.py

Snippet info

Language

Python

Visibility

public

Author

cuongquach.learning

Created

2016-09-19T16:34:37Z

Updated

2016-09-20T02:55:39Z

# Exercise 3.1
# Pyfml course
# Name : Quach Chi Cuong
# Glot.io : https://glot.io/snippets/eilhe3qtxn
# Requirement :
# input = 5 # (0b101) 
# output = 1
# 
# input = 24 (11000) 
# output = 1000
# 
# input = 9 (1001) 
# output = 1

# Nhap input la so nguyen
input = 24
count = 0
# Convert input sang binary
number_bin = bin(input)

for index in range(-1, -len(number_bin)-1, -1):
	# Phat hien ra dau '.' khi chay tu sau duoi chuoi vao, -> ten file co phan mo rong.
	if number_bin[index] == '1':
		if count == 0:
			position=index
			count = 1
			print('Input = \'',input,'\'\nBinary= \'',number_bin,'\'\nOutput = \'',number_bin[position:],'\'')
			break
INFO