Libraries
Bin16 Source Code
 previous   up   next 

Types
bin16
Binary values with 16 bits.

bin16

const type: bin16

Binary values with 16 bits. This type supports bitwise operations but no integer arithmetic. The internal representation is the same as for integer.


Operator Summary
bin16
(attr bin16) . value
Default value of bin16 (bin16(0)).
integer
(attr integer) conv (in bin16: bits)
Convert to integer.
bin16
(attr bin16) conv (in integer: anInt)
Convert to bin16.
string
(in bin16: bits) radix (in integer: base)
Convert a bin16 value to a string using a radix.
string
(in bin16: bits) RADIX (in integer: base)
Convert a bin16 value to a string using a radix.
boolean
(in bin16: bits1) = (in bin16: bits2)
Check if two bin16 values are equal.
boolean
(in bin16: bits1) <> (in bin16: bits2)
Check if two bin16 values are not equal.
bin16
(in bin16: bits1) & (in bin16: bits2)
Compute a bitwise and of two bin16 values.
bin16
(in bin16: bits1) | (in bin16: bits2)
Compute a bitwise inclusive or of two bin16 values.
bin16
(in bin16: bits1) >< (in bin16: bits2)
Compute a bitwise exclusive or (xor) of two bin16 values.
bin16
~ (in bin16: bits)
Compute a bitwise not of a bin16 value.
bin16
(in bin16: bits) << (in integer: lshift)
Compute bits logically left shifted by lshift.
bin16
(in bin16: bits) >> (in integer: rshift)
Compute bits logically right shifted by rshift.
void
(inout bin16: bits) <<:= (in integer: lshift)
Logical left shift bits by lshift and assign the result back to bits.
void
(inout bin16: bits) >>:= (in integer: rshift)
Logical right shift bits by rshift and assign the result back to bits.
void
(inout bin16: bits1) &:= (in bin16: bits2)
Compute a bitwise and and assign the result back to bits1.
void
(inout bin16: bits1) |:= (in bin16: bits2)
Compute a bitwise inclusive or and assign the result back to bits1.
void
(inout bin16: bits1) ><:= (in bin16: bits2)
Compute a bitwise exclusive or (xor) and assign the result back to bits1.

Function Summary
bin16
bin16 (in integer: number)
Convert to bin16.
bin16
bin16 (in char: ch)
Convert to bin16.
integer
ord (in bin16: bits)
Convert to integer.
integer
integer (in bin16: bits)
Convert to integer.
char
char (in bin16: bits)
Convert to char.
bin64
bin64 (in bin16: bits)
Convert to bin64.
bin16
bin16 (in bin64: bits)
Convert to bin16.
integer
compare (in bin16: bits1, in bin16: bits2)
Compare two bin16 values.
integer
hashCode (in bin16: bits)
Compute the hash value of a bin16 value.
bin16
rand (attr bin16)
Compute pseudo-random bin16 value.
integer
bitLength (in bin16: bits)
Number of bits in the minimum binary representation.
integer
lowestSetBit (in bin16: bits)
Number of lowest-order zero bits in the binary representation.
string
str (in bin16: bits)
Convert an bin16 value to a string.
string
bytes (in bin16: bits, BE, in integer: length)
Convert a bin16 into a string of bytes with big-endian encoding.
string
bytes (in bin16: bits, LE, in integer: length)
Convert a bin16 into a string of bytes with little-endian encoding.
bin16
rotLeft (in bin16: x, in integer: shiftCount)
Rotate the bits of a bin16 value left by shiftCount bits.
bin16
rotRight (in bin16: x, in integer: shiftCount)
Rotate the bits of a bin16 value right by shiftCount bits.
float
float (in bin16: bits)
Get a float from bits in IEEE 754 16-bit half-precision representation.
bin16
bin16 (in float: number)
Get bits in IEEE 754 16-bit half-precision representation from a float.
bin16
bin16 (in string: twoBytes, LE)
Convert a string of two little-endian bytes to a bin16 value.
bin16
bin16 (in string: twoBytes, BE)
Convert a string of two big-endian bytes to a bin16 value.

Operator Detail

. value

const bin16: (attr bin16) . value

Default value of bin16 (bin16(0)).


conv

const func integer: (attr integer) conv (in bin16: bits)

Convert to integer.

Returns:
the unchanged value as integer.

conv

const func bin16: (attr bin16) conv (in integer: anInt)

Convert to bin16.

Returns:
the unchanged value as bin16.

radix

const func string: (in bin16: bits) radix (in integer: base)

Convert a bin16 value to a string using a radix. The conversion uses the numeral system with the given base. Digit values from 10 upward are encoded with lower case letters. E.g.: 10 is encoded with a, 11 with b, etc.

bin16(48879) radix 16   returns "beef"
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If base < 2 or base > 36 holds.
MEMORY_ERROR - Not enough memory to represent the result.

RADIX

const func string: (in bin16: bits) RADIX (in integer: base)

Convert a bin16 value to a string using a radix. The conversion uses the numeral system with the given base. Digit values from 10 upward are encoded with upper case letters. E.g.: 10 is encoded with A, 11 with B, etc.

bin16(48879) RADIX 16   returns "BEEF"
Returns:
the string result of the conversion.
Raises:
RANGE_ERROR - If base < 2 or base > 36 holds.
MEMORY_ERROR - Not enough memory to represent the result.

=

const func boolean: (in bin16: bits1) = (in bin16: bits2)

Check if two bin16 values are equal.

Returns:
TRUE if the two values are equal, FALSE otherwise.

<>

const func boolean: (in bin16: bits1) <> (in bin16: bits2)

Check if two bin16 values are not equal.

Returns:
FALSE if both values are equal, TRUE otherwise.

&

const func bin16: (in bin16: bits1) & (in bin16: bits2)

Compute a bitwise and of two bin16 values.

bin16(2#1100) & bin16(2#1010)  returns  bin16(2#1000)
Returns:
the bitwise and of the two values.

|

const func bin16: (in bin16: bits1) | (in bin16: bits2)

Compute a bitwise inclusive or of two bin16 values.

bin16(2#1100) | bin16(2#1010)  returns  bin16(2#1110)
Returns:
the bitwise inclusive or of the two values.

><

const func bin16: (in bin16: bits1) >< (in bin16: bits2)

Compute a bitwise exclusive or (xor) of two bin16 values.

bin16(2#1100) >< bin16(2#1010)  returns  bin16(2#0110)
Returns:
the bitwise xor of the two values.

~

const func bin16: ~ (in bin16: bits)

Compute a bitwise not of a bin16 value.

~bin16(2#1)  returns  bin16(16#fffe)
Returns:
the bitwise not of the value.

<<

const func bin16: (in bin16: bits) << (in integer: lshift)

Compute bits logically left shifted by lshift.

bin16(16#abc) << 4  returns  bin16(16#abc0)
bin16(1) << 64         raises OVERFLOW_ERROR
Returns:
the left shifted value.
Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater equal 64.

>>

const func bin16: (in bin16: bits) >> (in integer: rshift)

Compute bits logically right shifted by rshift. Bits shifted beyond the lowest bit position are lost.

bin16(16#abcd) >> 4  returns  bin16(16#abc)
Returns:
the right shifted value.
Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater equal 64.

<<:=

const proc: (inout bin16: bits) <<:= (in integer: lshift)

Logical left shift bits by lshift and assign the result back to bits.

Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater equal 64.

>>:=

const proc: (inout bin16: bits) >>:= (in integer: rshift)

Logical right shift bits by rshift and assign the result back to bits. Bits shifted beyond the lowest bit position are lost.

Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater equal 64.

&:=

const proc: (inout bin16: bits1) &:= (in bin16: bits2)

Compute a bitwise and and assign the result back to bits1.


|:=

const proc: (inout bin16: bits1) |:= (in bin16: bits2)

Compute a bitwise inclusive or and assign the result back to bits1.


><:=

const proc: (inout bin16: bits1) ><:= (in bin16: bits2)

Compute a bitwise exclusive or (xor) and assign the result back to bits1.


Function Detail

bin16

const func bin16: bin16 (in integer: number)

Convert to bin16.

Returns:
the unchanged value as bin16.

bin16

const func bin16: bin16 (in char: ch)

Convert to bin16.

Returns:
the unchanged value as bin16.
Raises:
RANGE_ERROR - If the result does not fit into 16 bits.

ord

const func integer: ord (in bin16: bits)

Convert to integer.

Returns:
the unchanged value as integer.

integer

const func integer: integer (in bin16: bits)

Convert to integer.

Returns:
the unchanged value as integer.

char

const func char: char (in bin16: bits)

Convert to char.

Returns:
the unchanged value as char.

bin64

const func bin64: bin64 (in bin16: bits)

Convert to bin64.

Returns:
the unchanged value as bin64.

bin16

const func bin16: bin16 (in bin64: bits)

Convert to bin16.

Returns:
the unchanged value as bin16.

compare

const func integer: compare (in bin16: bits1, in bin16: bits2)

Compare two bin16 values.

Returns:
-1, 0 or 1 if the first argument is considered to be respectively less than, equal to, or greater than the second.

hashCode

const func integer: hashCode (in bin16: bits)

Compute the hash value of a bin16 value.

Returns:
the hash value.

rand

const func bin16: rand (attr bin16)

Compute pseudo-random bin16 value. The random values are uniform distributed.

Returns:
a random bin16 value.

bitLength

const func integer: bitLength (in bin16: bits)

Number of bits in the minimum binary representation. Leading zero bits are not part of the minimum binary representation.

bitLength(bin16(0))  returns 0
bitLength(bin16(1))  returns 1
bitLength(bin16(4))  returns 3
Returns:
the number of bits.

lowestSetBit

const func integer: lowestSetBit (in bin16: bits)

Number of lowest-order zero bits in the binary representation. This is equal to the index of the lowest-order one bit (indices start with 0). If there are only zero bits (bits is bin16(0)) the result is -1.

lowestSetBit(bin16(0))  returns -1
lowestSetBit(bin16(1))  returns  0
lowestSetBit(bin16(4))  returns  2
Returns:
the number of lowest-order zero bits or -1 for lowestSetBit(bin16(0)).

str

const func string: str (in bin16: bits)

Convert an bin16 value to a string. The values is converted to a string with decimal representation.

Returns:
the string result of the conversion.
Raises:
MEMORY_ERROR - Not enough memory to represent the result.

bytes

const func string: bytes (in bin16: bits, BE, in integer: length)

Convert a bin16 into a string of bytes with big-endian encoding. The result uses binary representation with a base of 256. The result contains chars (bytes) with an ordinal <= 255.

bytes(bin16(20299), BE, 3)  returns "\0;OK"
bytes(bin16(20299), BE, 2)  returns "OK"
bytes(bin16(20299), BE, 1)  raises RANGE_ERROR
Parameters:
bits - Bin16 to be converted.
length - Determines the length of the result string.
Returns:
a string of length bytes with the unsigned binary representation of bits.
Raises:
RANGE_ERROR - If length is negative or zero, or if the result would not fit in length bytes.
MEMORY_ERROR - Not enough memory to represent the result.

bytes

const func string: bytes (in bin16: bits, LE, in integer: length)

Convert a bin16 into a string of bytes with little-endian encoding. The result uses binary representation with a base of 256. The result contains chars (bytes) with an ordinal <= 255.

bytes(bin16(20299), LE, 3)  returns "OK\0;"
bytes(bin16(20299), LE, 2)  returns "OK"
bytes(bin16(20299), LE, 1)  raises RANGE_ERROR
Parameters:
bits - Bin16 to be converted.
length - Determines the length of the result string.
Returns:
a string of length bytes with the unsigned binary representation of bits.
Raises:
RANGE_ERROR - If length is negative or zero, or if the result would not fit in length bytes.
MEMORY_ERROR - Not enough memory to represent the result.

rotLeft

const func bin16: rotLeft (in bin16: x, in integer: shiftCount)

Rotate the bits of a bin16 value left by shiftCount bits. The vacant bit positions at the right side are filled in with the bits that are shifted out at the left side.

rotLeft(bin16(16#1234), 4)  returns  bin16(16#2341)
Returns:
the left rotated value.
Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater than 16.

rotRight

const func bin16: rotRight (in bin16: x, in integer: shiftCount)

Rotate the bits of a bin16 value right by shiftCount bits. The vacant bit positions at the left side are filled in with the bits that are shifted out at the right side.

rotRight(bin16(16#1234), 4)  returns  bin16(16#4123)
Returns:
the right rotated value.
Raises:
OVERFLOW_ERROR - If the shift amount is negative or greater than 16.

float

const func float: float (in bin16: bits)

Get a float from bits in IEEE 754 16-bit half-precision representation. IEEE 754 is a standard for floating point arithmetic. The 16-bit half-precision format of IEEE 754 (called FP16 or float16) has a sign bit, a 5 bit exponent, and a 10 bit mantissa.

float(bin16(16#3c00))  returns  1.0
Parameters:
bits - 16 bits to be converted to a float.
Returns:
a float from 16 bits in half-precision float representation.

bin16

const func bin16: bin16 (in float: number)

Get bits in IEEE 754 16-bit half-precision representation from a float. IEEE 754 is a standard for floating point arithmetic. The 16-bit half-precision format of IEEE 754 (called FP16 or float16) has a sign bit, a 5 bit exponent, and a 10 bit mantissa.

bin16(1.0)  returns  bin16(16#3c00)
Parameters:
number - Float value to be converted to bin16.
Returns:
16 bits in IEEE 754 half-precision float representation.

bin16

const func bin16: bin16 (in string: twoBytes, LE)

Convert a string of two little-endian bytes to a bin16 value.

Returns:
the bin16 value.

bin16

const func bin16: bin16 (in string: twoBytes, BE)

Convert a string of two big-endian bytes to a bin16 value.

Returns:
the bin16 value.


 previous   up   next