Libraries |
|
Bin32 | Source Code |
|
|
Types | ||||
|
bin32
const type: bin32
-
Binary values with 32 bits. This type supports bitwise operations but no integer arithmetic. The internal representation is the same as for integer.
Operator Summary | |||||
bin32 |
| ||||
integer |
| ||||
bin32 |
| ||||
string |
| ||||
string |
| ||||
boolean |
| ||||
boolean |
| ||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
void |
| ||||
void |
| ||||
void |
| ||||
void |
| ||||
void |
|
Function Summary | |||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
integer |
| ||||
integer |
| ||||
float |
| ||||
integer |
| ||||
integer |
| ||||
bin32 |
| ||||
integer |
| ||||
integer |
| ||||
string |
| ||||
string |
| ||||
string |
| ||||
bin32 |
| ||||
bin32 |
| ||||
bin32 |
| ||||
float |
| ||||
bin32 |
| ||||
bin32 |
|
Operator Detail |
conv
const func integer: (attr integer) conv (in bin32: bits)
-
Convert to integer.
- Returns:
- the unchanged value as integer.
conv
const func bin32: (attr bin32) conv (in integer: anInt)
-
Convert to bin32.
- Returns:
- the unchanged value as bin32.
radix
const func string: (in bin32: bits) radix (in integer: base)
-
Convert a bin32 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.
bin32(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 bin32: bits) RADIX (in integer: base)
-
Convert a bin32 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.
bin64(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 bin32: bits1) = (in bin32: bits2)
-
Check if two bin32 values are equal.
- Returns:
- TRUE if the two values are equal, FALSE otherwise.
<>
const func boolean: (in bin32: bits1) <> (in bin32: bits2)
-
Check if two bin32 values are not equal.
- Returns:
- FALSE if both values are equal, TRUE otherwise.
&
const func bin32: (in bin32: bits1) & (in bin32: bits2)
-
Compute a bitwise and of two bin32 values.
bin32(2#1100) & bin32(2#1010) returns bin32(2#1000)
- Returns:
- the bitwise and of the two values.
|
const func bin32: (in bin32: bits1) | (in bin32: bits2)
-
Compute a bitwise inclusive or of two bin32 values.
bin32(2#1100) | bin32(2#1010) returns bin32(2#1110)
- Returns:
- the bitwise inclusive or of the two values.
><
const func bin32: (in bin32: bits1) >< (in bin32: bits2)
-
Compute a bitwise exclusive or (xor) of two bin32 values.
bin32(2#1100) >< bin32(2#1010) returns bin32(2#0110)
- Returns:
- the bitwise xor of the two values.
~
const func bin32: ~ (in bin32: bits)
-
Compute a bitwise not of a bin32 value.
~bin32(2#1) returns bin32(16#fffffffe)
- Returns:
- the bitwise not of the value.
<<
const func bin32: (in bin32: bits) << (in integer: lshift)
-
Compute bits logically left shifted by lshift.
bin32(16#abcdef) << 4 returns bin32(16#abcdef0) bin32(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 bin32: (in bin32: bits) >> (in integer: rshift)
-
Compute bits logically right shifted by rshift. Bits shifted beyond the lowest bit position are lost.
bin32(16#abcdef) >> 4 returns bin32(16#abcde)
- Returns:
- the right shifted value.
- Raises:
- OVERFLOW_ERROR - If the shift amount is negative or greater equal 64.
<<:=
const proc: (inout bin32: 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 bin32: 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 bin32: bits1) &:= (in bin32: bits2)
-
Compute a bitwise and and assign the result back to bits1.
|:=
const proc: (inout bin32: bits1) |:= (in bin32: bits2)
-
Compute a bitwise inclusive or and assign the result back to bits1.
><:=
const proc: (inout bin32: bits1) ><:= (in bin32: bits2)
-
Compute a bitwise exclusive or (xor) and assign the result back to bits1.
Function Detail |
bin32
const func bin32: bin32 (in integer: number)
-
Convert to bin32.
- Returns:
- the unchanged value as bin32.
bin32
const func bin32: bin32 (in char: ch)
-
Convert to bin32.
- Returns:
- the unchanged value as bin32.
bin32
const func bin32: bin32 (in float: number)
-
Get bits in IEEE 754 single-precision representation from a float. IEEE 754 is a standard for floating point arithmetic. The single-precision format of IEEE 754 has a sign bit, an 8 bit exponent, and a 23 bit mantissa.
bin32(1.0) returns bin32(16#3f800000)
- Parameters:
- number - Float value to be converted to bin32.
- Returns:
- 32 bits in IEEE 754 single-precision float representation.
ord
const func integer: ord (in bin32: bits)
-
Convert to integer.
- Returns:
- the unchanged value as integer.
integer
const func integer: integer (in bin32: bits)
-
Convert to integer.
- Returns:
- the unchanged value as integer.
float
const func float: float (in bin32: bits)
-
Get a float from bits in IEEE 754 single-precision representation. IEEE 754 is a standard for floating point arithmetic. The single-precision format of IEEE 754 has a sign bit, an 8 bit exponent, and a 23 bit mantissa.
float(bin32(16#3f800000)) returns 1.0
- Parameters:
- bits - Bits to be converted to a float.
- Returns:
- a float from bits in single-precision float representation.
compare
const func integer: compare (in bin32: bits1, in bin32: bits2)
-
Compare two bin32 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 bin32: bits)
-
Compute the hash value of a bin32 value.
- Returns:
- the hash value.
rand
const func bin32: rand (attr bin32)
-
Compute pseudo-random bin32 value. The random values are uniform distributed.
- Returns:
- a random bin32 value.
bitLength
const func integer: bitLength (in bin32: bits)
-
Number of bits in the minimum binary representation. Leading zero bits are not part of the minimum binary representation.
bitLength(bin32(0)) returns 0 bitLength(bin32(1)) returns 1 bitLength(bin32(4)) returns 3
- Returns:
- the number of bits.
lowestSetBit
const func integer: lowestSetBit (in bin32: 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 bin32(0)) the result is -1.
lowestSetBit(bin32(0)) returns -1 lowestSetBit(bin32(1)) returns 0 lowestSetBit(bin32(4)) returns 2
- Returns:
- the number of lowest-order zero bits or -1 for lowestSetBit(bin32(0)).
str
const func string: str (in bin32: bits)
-
Convert an bin32 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 bin32: bits, BE, in integer: length)
-
Convert a bin32 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(bin32(1413829460), BE, 5) returns "\0;TEST" bytes(bin32(1413829460), BE, 4) returns "TEST" bytes(bin32(1413829460), BE, 3) raises RANGE_ERROR
- Parameters:
- bits - Bin32 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 bin32: bits, LE, in integer: length)
-
Convert a bin32 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(bin32(1413829460), LE, 5) returns "TEST\0;" bytes(bin32(1413829460), LE, 4) returns "TEST" bytes(bin32(1413829460), LE, 3) raises RANGE_ERROR
- Parameters:
- bits - Bin32 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 bin32: rotLeft (in bin32: x, in integer: shiftCount)
-
Rotate the bits of a bin32 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(bin32(16#12345678), 8) returns bin32(16#34567812)
- Returns:
- the left rotated value.
- Raises:
- OVERFLOW_ERROR - If the shift amount is negative or greater than 32.
rotRight
const func bin32: rotRight (in bin32: x, in integer: shiftCount)
-
Rotate the bits of a bin32 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(bin32(16#12345678), 8) returns bin32(16#78123456)
- Returns:
- the right rotated value.
- Raises:
- OVERFLOW_ERROR - If the shift amount is negative or greater than 32.
float2MbfBits
const func bin32: float2MbfBits (in float: number, SINGLE)
-
Get bits in MBF single-precision representation from a float. Microsoft Binary Format (MBF) is a format for floating point numbers. The single-precision version of MBF has a 8 bit exponent, a sign bit and a 23 bit mantissa.
float2MbfBits(1.0, SINGLE) returns bin32(16#81000000)
- Parameters:
- number - Float value to be converted to bin32.
- Returns:
- 32 bits in MBF single-precision float representation.
- Raises:
- RANGE_ERROR - If number is not representable in MBF. NaN, Infinity and -Infinity are not representable in MBF. Numbers with an absolute value larger than 1.7014117331926443e+38 are also not representable in MBF.
mbfBits2Float
const func float: mbfBits2Float (in bin32: bits)
-
Get a float from bits in MBF single-precision representation. Microsoft Binary Format (MBF) is a format for floating point numbers. The single-precision version of MBF has a 8 bit exponent, a sign bit and a 23 bit mantissa.
mbfBits2Float(bin32(16#81000000)) returns 1.0
- Parameters:
- bits - Bits to be converted to a float.
- Returns:
- a float from bits in MBF single-precision float representation.
bin32
const func bin32: bin32 (in string: fourBytes, LE)
-
Convert a string of four little-endian bytes to a bin32 value.
- Returns:
- the bin32 value.
bin32
const func bin32: bin32 (in string: fourBytes, BE)
-
Convert a string of four big-endian bytes to a bin32 value.
- Returns:
- the bin32 value.
|
|