Boolean to byte kotlin

Byte

Represents a 8-bit signed integer. On the JVM, non-nullable values of this type are represented as values of the primitive type byte .

Functions

operator fun compareTo(other: Byte): Int
operator fun compareTo(other: Short): Int
operator fun compareTo(other: Int): Int
operator fun compareTo(other: Long): Int
operator fun compareTo(other: Float): Int
operator fun compareTo(other: Double): Int

Compares this value with the specified value for order. Returns zero if this value is equal to the specified other value, a negative number if it’s less than other, or a positive number if it’s greater than other.

operator fun div(other: Byte): Int
operator fun div(other: Short): Int
operator fun div(other: Int): Int
operator fun div(other: Long): Long
operator fun div(other: Float): Float
operator fun div(other: Double): Double

Divides this value by the other value.

operator fun minus(other: Byte): Int
operator fun minus(other: Short): Int
operator fun minus(other: Int): Int
operator fun minus(other: Long): Long
operator fun minus(other: Float): Float
operator fun minus(other: Double): Double

Subtracts the other value from this value.

operator fun plus(other: Byte): Int
operator fun plus(other: Short): Int
operator fun plus(other: Int): Int
operator fun plus(other: Long): Long
operator fun plus(other: Float): Float
operator fun plus(other: Double): Double

Adds the other value to this value.

operator fun rangeTo(other: Byte): IntRange
operator fun rangeTo(other: Short): IntRange
operator fun rangeTo(other: Int): IntRange
operator fun rangeTo(other: Long): LongRange

Creates a range from this value to the specified other value.

operator fun rem(other: Byte): Int
operator fun rem(other: Short): Int
operator fun rem(other: Int): Int
operator fun rem(other: Long): Long
operator fun rem(other: Float): Float
operator fun rem(other: Double): Double

Calculates the remainder of dividing this value by the other value.

operator fun times(other: Byte): Int
operator fun times(other: Short): Int
operator fun times(other: Int): Int
operator fun times(other: Long): Long
operator fun times(other: Float): Float
operator fun times(other: Double): Double

Multiplies this value by the other value.

Читайте также:  Иерархические структуры данных python

Returns the value of this number as a Byte, which may involve rounding or truncation.

Returns the Char with the numeric value equal to this number, truncated to 16 bits if appropriate.

Returns the value of this number as a Double, which may involve rounding.

Returns the value of this number as a Float, which may involve rounding.

Returns the value of this number as an Int, which may involve rounding or truncation.

Returns the value of this number as a Long, which may involve rounding or truncation.

Returns the value of this number as a Short, which may involve rounding or truncation.

operator fun unaryMinus(): Int

Returns the negative of this value.

operator fun unaryPlus(): Int

Companion Object Properties

A constant holding the maximum value an instance of Byte can have.

A constant holding the minimum value an instance of Byte can have.

Extension Functions

infix fun Byte.and(other: Byte): Byte

Performs a bitwise AND operation between the two values.

fun Byte.coerceAtLeast(minimumValue: Byte): Byte

Ensures that this value is not less than the specified minimumValue.

fun Byte.coerceAtMost(maximumValue: Byte): Byte

Ensures that this value is not greater than the specified maximumValue.

fun Byte.coerceIn( minimumValue: Byte, maximumValue: Byte ): Byte

Ensures that this value lies in the specified range minimumValue..maximumValue.

infix fun Byte.downTo(to: Byte): IntProgression
infix fun Byte.downTo(to: Int): IntProgression
infix fun Byte.downTo(to: Long): LongProgression
infix fun Byte.downTo(to: Short): IntProgression

Returns a progression from this value down to the specified to value with the step -1.

Inverts the bits in this value.

infix fun Byte.or(other: Byte): Byte

Performs a bitwise OR operation between the two values.

fun Byte.toString(radix: Int): String

Returns a string representation of this Byte value in the specified radix.

infix fun Byte.until(to: Byte): IntRange
infix fun Byte.until(to: Int): IntRange
infix fun Byte.until(to: Long): LongRange
infix fun Byte.until(to: Short): IntRange

Returns a range from this value up to but excluding the specified to value.

infix fun Byte.xor(other: Byte): Byte

Performs a bitwise XOR operation between the two values.

Источник

Boolean

Represents a value which is either true or false . On the JVM, non-nullable values of this type are represented as values of the primitive type boolean .

Functions

and

Performs a logical and operation between this Boolean and the other one. Unlike the && operator, this function does not perform short-circuit evaluation. Both this and other will always be evaluated.

infix fun and(other: Boolean): Boolean

compareTo

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it’s less than other, or a positive number if it’s greater than other.

fun compareTo(other: Boolean): Int

equals

fun equals(other: Boolean): Boolean

Indicates whether some other object is «equal to» this one. Implementations must fulfil the following requirements:

fun equals(other: Any?): Boolean

hashCode

Returns a hash code value for the object. The general contract of hashCode is:

not

Returns the inverse of this boolean.

or

Performs a logical or operation between this Boolean and the other one. Unlike the || operator, this function does not perform short-circuit evaluation. Both this and other will always be evaluated.

infix fun or(other: Boolean): Boolean

toString

Returns a string representation of the object.

xor

Performs a logical xor operation between this Boolean and the other one.

infix fun xor(other: Boolean): Boolean

Extension Functions

coerceAtLeast

Ensures that this value is not less than the specified minimumValue.

fun > T.coerceAtLeast(minimumValue: T): T

coerceAtMost

Ensures that this value is not greater than the specified maximumValue.

fun > T.coerceAtMost(maximumValue: T): T

coerceIn

Ensures that this value lies in the specified range minimumValue..maximumValue.

fun > T.coerceIn( minimumValue: T?, maximumValue: T? ): T

Ensures that this value lies in the specified range.

fun > T.coerceIn( range: ClosedFloatingPointRangeT> ): T
fun > T.coerceIn(range: ClosedRangeT>): T

compareTo

Compares this object with the specified object for order. Returns zero if this object is equal to the specified other object, a negative number if it’s less than other, or a positive number if it’s greater than other.

infix fun Comparable .compareTo(other: T): Int

rangeTo

Creates a range from this Comparable value to the specified that value.

operator fun > T.rangeTo( that: T ): ClosedRange

rangeUntil

Creates an open-ended range from this Comparable value to the specified that value.

operator fun > T.rangeUntil( that: T ): OpenEndRange

toByte

Источник

Boolean

Представляет значение, которое может быть true или false . В JVM значения этого типа, не допускающие значения NULL, представлены как значения boolean примитивного типа .

Functions

and

Выполняет логические and операции между этим Boolean и другой один. В отличие от оператора && , эта функция не выполняет оценку короткого замыкания. И this и другое всегда будут оцениваться.

infix fun and(other: Boolean): Boolean

compareTo

Сравнивает этот объект с указанным объектом для заказа. Возвращает ноль, если этот объект равен указанному другому объекту, отрицательное число, если оно меньше другого , или положительное число, если оно больше другого .

fun compareTo(other: Boolean): Int

equals

fun equals(other: Boolean): Boolean

Указывает на то,что какой-то другой объект «равен» этому.Введение должно отвечать следующим требованиям:

fun equals(other: Any?): Boolean

hashCode

Возвращает значение хэш-кода для объекта. Общий контракт hashCode :

not

Возвращает обратную сторону этого булева.

or

Выполняет логическую операцию or между этим логическим значением и другим . В отличие от || оператора, эта функция не выполняет оценку короткого замыкания. И this и другое всегда будут оцениваться.

infix fun or(other: Boolean): Boolean

toString

Возвращает строковое представление объекта.

xor

Выполняет логическую операцию xor между этим логическим значением и другим .

infix fun xor(other: Boolean): Boolean

Extension Functions

coerceAtLeast

Гарантирует, что это значение не меньше указанного минимального значения .

fun > T.coerceAtLeast(minimumValue: T): T

coerceAtMost

Гарантирует, что это значение не превышает указанное значение maximumValue .

fun > T.coerceAtMost(maximumValue: T): T

coerceIn

Гарантирует, что это значение находится в указанном диапазоне minimumValue .. maximumValue .

fun > T.coerceIn( minimumValue: T?, maximumValue: T? ): T

Гарантирует, что это значение находится в указанном диапазоне .

fun > T.coerceIn( range: ClosedFloatingPointRangeT> ): T
fun > T.coerceIn(range: ClosedRangeT>): T

compareTo

Сравнивает этот объект с указанным объектом для заказа. Возвращает ноль, если этот объект равен указанному другому объекту, отрицательное число, если оно меньше другого , или положительное число, если оно больше другого .

infix fun Comparable .compareTo(other: T): Int

rangeTo

Создает диапазон от этого Сопоставимых значений до заданного этого значения.

operator fun > T.rangeTo( that: T ): ClosedRange

rangeUntil

Создает открытый диапазон от этого сопоставимого значения до указанного этого значения.

operator fun > T.rangeUntil( that: T ): OpenEndRange

toByte

Источник

Byte Data type Usage and Type Conversion in Kotlin

Thus a Byte value can be declared in 2 ways as mentioned below.

1. Mentioning type explicitly

val variable_name : Byte = value for example, val number : Byte = 20

2. Declaring and Initializing separately

var variable_name : Byte variable_name = value for example //Declaring and Initializing separately var number:Byte number = -50

Byte Datatype Example Program in Kotlin

// Byte Datatype Kotlin example program // Data type Kotlin Programs, Basic Kotlin Programs fun main(args:Array) < //Assigning value to Byte variable explicitly val a:Byte = 100 val b:Byte = -50 println("The byte is: $a") println("The byte is: $b") >

Sample Output

The byte is: 100 The byte is: -50

Type conversion syntax and declaration

//String to Byte Conversion val variable_name = "string".toByte() //Int to Byte Conversion val variable_name = int_variable.toByte()

Byte type Conversion Example Program in Kotlin

// Byte Datatype Kotlin example program // Data type Kotlin Programs, Basic Kotlin Programs fun main(args: Array < String >) < //Converted from String and Byte type is inferred val num1 = "50".toByte() //Conversion from String and Declaring an Byte value immediately val num2: Byte = "30".toByte() val num3: Int = 10 //Conversion from Int val num4: Byte = num3.toByte() val num5: Float = 20.31f //Conversion from Float val num6: Byte = num5.toByte() //Print values after conversion println("String to Byte : num1 Value : $num1") println("String to Byte : num2 Value : $num2") println("Int Value : num3 Value : $num3") println("Int to Byte : num4 Value : $num4") println("Float Value : num5 Value : $num5") println("Float to Byte : num6 Value : $num6") >

Sample Output

String to Byte : num1 Value : 50 String to Byte : num2 Value : 30 Int Value : num3 Value : 10 Int to Byte : num4 Value : 10 Float Value : num5 Value : 20.31 Float to Byte : num6 Value : 20

Kotlin Data Types

  1. Int Data type Usage and Type Conversion in Kotlin
  2. Float Data type Usage and Type Conversion in Kotlin
  3. Double Data type Usage and Type Conversion in Kotlin
  4. Byte Data type Usage and Type Conversion in Kotlin
  5. Short Data type Usage and Type Conversion in Kotlin
  6. Long Data type Usage and Type Conversion in Kotlin
  7. Char Data type Usage and Type Conversion in Kotlin
  8. Boolean Data type Usage and Type Conversion in Kotlin
  9. Number Data type Usage and Type Conversion in Kotlin
  10. String Data type Usage and Type Conversion in Kotlin
  11. Elvis Operator in Kotlin
  1. Read Data Input using Scanner in Kotlin
  2. Declare Variables In Kotlin
  3. Double Data type Usage and Type Conversion in Kotlin
  4. print and println Data Output in Kotlin
  5. Arithmetic Operators (Mathematical Operators) in Kotlin
  6. Unary Operators (Sign, Inverts, Increment, and Decrement) in Kotlin
  7. Printing Variables and Values in Kotlin
  8. Float Data type Usage and Type Conversion in Kotlin
  9. Equality Operators (==, !=) and Referential equality Operators (===, !==) in Kotlin
  10. Long Data type Usage and Type Conversion in Kotlin
  11. Comparison Operators in Kotlin
  12. Byte Data type Usage and Type Conversion in Kotlin
  13. In Operator (in and !in) in Kotlin
  14. Is Operator (is and !is) in Kotlin
  15. Assignment Operators and Augmented Assignment Operators in Kotlin
  16. Read Data Input from Command Line in Kotlin
  17. Read String Data Input in Kotlin
  18. Indexed Access Operator [, ] in Kotlin
  19. Char Data type Usage and Type Conversion in Kotlin
  20. Elvis Operator (?:) in Kotlin
  21. Not Null Assertion(!!) Operator in Kotlin
  22. Logical Operators in Kotlin
  23. Safe Call Operator (?.) in Kotlin
  24. Repeat and Its Usage in Kotlin
  25. Boolean Data type Usage and Type Conversion in Kotlin

Источник

Оцените статью