Class Byte

Class represents a byte. Byte can hold 8 bits, out of which one bit is reserved for sign. Therefore range of values byte can hold is [-128..127].

Methods


(byte) copy

Creates a copy of source.

Return value

Example

main
  byte b1
  byte b2 = b1.copy     // b2 == 0
                

(byte) - <byte b>

Negates byte provided as parameter.

Parameters

Return value

Example

main
  byte b1 = 1.truncate
  byte b2 = -b1         // b2 == -1
                

(byte) <byte b1> + <byte b2>

Performs addition of two bytes.

Parameters

Return value

Example

main
  byte b1 = 1.truncate
  byte b2 = 2.truncate
  byte b3 = b1 + b2     // b3 == 3
                

(byte) <byte b1> - <byte b2>

Performs subtraction of two bytes.

Parameters

Return value

Example

main
  byte b1 = 1.truncate
  byte b2 = 2.truncate
  byte b3 = b1 - b2     // b3 == -1
                

(byte) <byte b1> * <byte b2>

Performs multiplication of two bytes.

Parameters

Return value

Example

main
  byte b1 = 4.truncate
  byte b2 = 2.truncate
  byte b3 = b1 * b2     // b3 == 8
                

(byte) <byte b1> / <byte b2>

Performs division of two bytes.

Parameters

Return value

Example

main
  byte b1 = 4.truncate
  byte b2 = 2.truncate
  byte b3 = b1 / b2     // b3 == 2
                

(byte) <byte b1> % <byte b2>

Performs division of two bytes and returns the remainder.

Parameters

Return value

Example

main
  byte b1 = 5.truncate
  byte b2 = 2.truncate
  byte b3 = b1 % b2     // b3 == 1
                

(byte) <byte b1> band <byte b2>

Performs bitwise AND on two bytes.

Parameters

Return value

Example

main
  byte b1 = 107.truncate  // b1 as binary: 0110 1011
  byte b2 = 38.truncate   // b2 as binary: 0010 0110
  byte b3 = b1 band b2    // b3 as binary: 0010 0010 (== 34)
                

(byte) <byte b1> bor <byte b2>

Performs bitwise OR on two bytes.

Parameters

Return value

Example

main
  byte b1 = 107.truncate  // b1 as binary: 0110 1011
  byte b2 = 38.truncate   // b2 as binary: 0010 0110
  byte b3 = b1 bor b2     // b3 as binary: 0110 1111 (== 111)
                

(byte) <byte b1> bxor <byte b2>

Performs bitwise XOR (=Exclusive OR) on two bytes.

Parameters

Return value

Example

main
  byte b1 = 107.truncate  // b1 as binary: 0110 1011
  byte b2 = 38.truncate   // b2 as binary: 0010 0110
  byte b3 = b1 bxor b2    // b3 as binary: 0100 1101 (== 77)
                

(byte) <byte b1> << <byte b2>

Performs a left shift to byte.

Parameters

Return value

Example

main
  byte b1 = 13.truncate        // b1 as binary: 0000 1101
  byte b2 = b1 << 1.truncate   // b2 as binary: 0001 1010 (== 26)
  byte b3 = b1 << 2.truncate   // b3 as binary: 0011 0100 (== 52)
                

(byte) <byte b1> >> <byte b2>

Performs a right shift to byte.

Parameters

Return value

Example

main
  byte b1 = 52.truncate           // b1 as binary: 0011 0100
  byte b2 = b1 >> 1.truncate      // b2 as binary: 0001 1010 (== 26)
  byte b3 = b1 >> 2.truncate      // b3 as binary: 0000 1101 (== 13)
                

<byte b1> += <byte b2>

Perform addition to byte.

Parameters

Example

main
  byte b = 10.truncate
  b += 12.truncate               // b == 24
                

<byte b1> -= <byte b2>

Perform subtraction from byte.

Parameters

Example

main
  byte b = 10.truncate
  b -= 12.truncate               // b == -2
                

<byte b1> *= <byte b2>

Perform multiplication to byte.

Parameters

Example

main
  byte b = 5.truncate
  b *= 6.truncate               // b == 30
                

<byte b1> /= <byte b2>

Perform division to byte.

Parameters

Example

main
  byte b = 18.truncate
  b /= 6.truncate               // b == 3
                

<byte b1> %= <byte b2>

Perform division to byte and set remainder as value. ????

Parameters

Example

main
  byte b = 20.truncate
  b %= 6.truncate               // b == 2
                

<byte b1> &= <byte b2>

Perform binary AND to byte.

Parameters

Example

main
  byte b1 = 107.truncate           // b1 as binary: 0110 1011
  byte b2 = 38.truncate            // b2 as binary: 0010 0110
  b1 &= b2                         // b1 as binary: 0010 0010 (== 34)
                

<byte b1> |= <byte b2>

Perform binary OR to byte.

Parameters

Example

main
  byte b1 = 107.truncate           // b1 as binary: 0110 1011
  byte b2 = 38.truncate            // b2 as binary: 0010 0110
  b1 |= b2                         // b1 as binary: 0110 1111 (== 111)
                

<byte b1> ^= <byte b2>

Perform binary XOR (=Exclusive OR) to byte.

Parameters

Example

main
  byte b1 = 107.truncate  // b1 as binary: 0110 1011
  byte b2 = 38.truncate   // b2 as binary: 0010 0110
  b1 ^= b2                // b1 as binary: 0100 1101 (== 77)
                

<byte b1> <<= <byte b2>

Perform a left shift to byte.

Parameters

Example

main
  byte b = 13.truncate        // b as binary: 0000 1101
  b <<= 1.truncate            // b as binary: 0001 1010 (== 26)
  b <<= 2.truncate            // b as binary: 0110 1000 (== 104)
                

<byte b1> >>= <byte b2>

Perform a right shift to byte.

Parameters

Example

main
  byte b = 104.truncate           // b as binary: 0110 1000
  b >>= 1.truncate                // b as binary: 0011 0100 (== 52)
  b >>= 2.truncate                // b as binary: 0000 1101 (== 13)
                

<byte value>++

Increment value by one.

Parameters

Example

main
  byte b = 101.truncate
  b++                           // b == 102
                

<byte value>--

Decrement value by one.

Parameters

Example

main
  byte b = 101.truncate
  b--                           // b == 100
                

(bool) <byte b1> == <byte b2>

Test whether parameters have the same value.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  byte b2 = 11.truncate
  bool result = b1 == b2        // result == false
                

(bool) <byte b1> < <byte b2>

Performs a comparison whether first parameter is smaller than second.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  byte b2 = 11.truncate
  bool result = b1 < b2         // result == true
                

(bool) <byte b1> <= <byte b2>

Performs a comparison whether first parameter is smaller or equal to the second parameter.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  b1++
  byte b2 = 11.truncate
  bool result = b1 <= b2        // result == true
                

(bool) <byte b1> != <byte b2>

Test whether parameters are not equal.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  byte b2 = 11.truncate
  bool result = b1 != b2         // result == true
                

(bool) <byte b1> > <byte b2>

Performs comparison whether first parameter is larger than second.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  byte b2 = 11.truncate
  bool result = b1 > b2         // result == false
                

(bool) <byte b1> >= <byte b2>

Performs comparison whether first parameter is larger or equals the second paramer.

Parameters

Return value

Example

main
  byte b1 = 10.truncate
  b1++
  byte b2 = 11.truncate
  bool result = b1 >= b2        // result == true
                

(byte) byte .minimum value

Minimum value a byte can contain..

Return value

Example

main
  byte b = byte.minimum value   // b == -128
                

(byte) byte .maximum value

Maximum value a byte can contain.

Return value

Example

main
  byte b = byte.maximum value   // b == 127
                

(string) <byte b>

Returns byte as string.

Parameters

Return value

Example

main
  byte b = 100.truncate         // b == 100
  string s = b                  // s == '100'
                

(int) <byte b>

Returns byte as int.

Parameters

Return value

Example

main
  byte b = 100.truncate         // b == 100
  int i = b                     // i == 100
                

(byte) abs

Returns absolute value of byte.

Return value

Example

main
  byte b1 = (-100).truncate         // b1 == -100
  byte b2 = b1.abs                  // b2 == 100