Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun main(args: Array<String>) {
print("Nhap so he thap phan:")
var number = readLine()!!.toLong()
var binary = binary(number)
print("Dang nhi phan la: $binary")
fun binary( _number:Long):Long{
// Function parameters in Kotlin are read-only val's inside the function,
// so _number here will always refer to the original object that was passed in.
// If you need to modify what it points to while your function is running,
// you'll have to make a local copy of it at the beginning of the function, and then you can make that a var.
var number = _number
var base:Long = 1L
var binary_val:Long =0L
var rem:Long
while(number > 0){
rem = number % 2
binary_val = binary_val + rem * base
number /= 2
base = base * 10
return binary_val;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.