Show/Hide Toolbars

XSharp

The BINARY type is represented a series of bytes.

 

Binary literals are written as 0h12345678abcdef

The value behind 0h is a sequence of hex numbers. Each pair of hex numbers (nibble) represents 1 byte. There must be an even number of 'nibbles'.

The binary literals are encoded in an array of bytes. In the Core dialect the binary literals are represented as a byte[]. In the other dialects the binary literals are a new type (XSharp.__Binary) which can be specified as the new BINARY keyword.

The UsualType() of BINARY is 29.

The XSharp.__Binary type has operators to add a string to a binary and add a binary to a string.
Binary + String will return a Binary
String + Binary will return a String
Binary + Binary will return a Binary.
There are also comparison operators on the Binary type (>, <, >=, <=). These will use the string comparison routines that are defined with SetCollation()  with the exception that an = comparison with a single equals operator does not return TRUE when the Right hand side is shorter than the Left hand side and the first bytes match.

Conversions from Binary to String are done with the Encoding.GetBytes() and Encoding.GetString() functions for the current Windows Encoding.
That means that on single byte code pages each character in the string will result in one byte and each byte will result in one character.
For multibyte code pages (Chinese, Japanese, Korean etc) some characters will result in more than one byte and some byte pairs will result in a single character.

There are implicit operators that convert a BINARY to a byte[] and back. There are also implicit operators that convert a Binary to a String and back.

When compiling with the Vulcan Runtime then the byte[] array is stored in a USUAL value for the non core dialects.

Implementation

The BINARY type is implemented in the class XSharp.__Binary
The Usualtype of BINARY has the value 29