Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I manually assign bytes to a long in Kotlin?

Tags:

java

kotlin

I am trying to do something like this in Kotlin:

val top : Long = 1000000_1000000_1000000_1000000_1000000_1000000_1000000

In Java it looks like this:

long TOP = 1000000_1000000_1000000_1000000_1000000_1000000_1000000L;

The Java version works just fine, in Kotlin I get an error:

The value is out of range

Does anyone have an idea on how to do it? Thanks in advance.

like image 984
D1amxnd Avatar asked Jul 08 '20 11:07

D1amxnd


1 Answers

You can do like below in Kotlin, prefix 0b for Long representation.

val top : Long = 0b1000000_1000000_1000000_1000000_1000000_1000000_1000000

For more info on this, please check the documentation

like image 156
Shalu T D Avatar answered Oct 29 '22 09:10

Shalu T D