Is there a method that can be used to get an Integer's representation in bits? For example when provided: 0 gives 0 4 gives 100 22 gives 10110

推荐答案

Method 1:

Note: This method works for both positive and negative integers.

Method 2: Use a.toString(2) where a is an Int, 2 is the radix Note: This method only works for positive integers.

Kotlin相关问答推荐

在KMM合成多平台中创建特定于平台的视图

为何Kotlin标准库中的AND和OR函数不能像&&和||一样进行短路运算?

Spring Boot Kotlin 数据类未使用 REST 控制器中的默认值初始化

为什么这两个 Kotlin 协程函数不一样?

Kotlin Path.useLines { } - 如何不获取 IOException("Stream closed")?

在 Kotlin 中,如何绑定扩展方法以在接收器范围函数中工作

mutableStateOf 在 Jetpack Compose 中不记住 API 的情况下保持重组后的值

Eclipse:无法安装 Kotlin 插件

Kotlin:伴随对象内的函数扩展

从 Kotlin 调用 Java 时可以为空的规则是什么

如何连接两个 kotlin 流?

如何使用 Kotlin KClass 属性 simpleName 生成空值

如何为 material.Slider 视图创建绑定适配器?

java - 如何将函数作为参数从java传递给kotlin方法?

无法删除部分子项.这可能是因为进程打开了文件或将其工作目录设置在目标目录中

如何使用 Coil 从 URL 获取位图?

无法在Kotlin中使用argb color int值?

Kotlin Flow 收集后无法执行代码

Android studio,构建kotlin时出现奇怪错误:生成错误代码

Android room DAO 接口不适用于继承