dr

 

The data representation of intrinsic objects in .Net can be determined and manipulated using ⎕dr.

⎕dr can be used either monadically or dyadically.

 

Monadic:

When used monadically ⎕dr reports the type of an object based on legacy codes.  These codes are:

Code

Description

11:

boolean (true/false, not bit)

81:

bytes

82:

chars (compatible with 82 in existing system)

83:

reserved.

162:

chars (compatible with 82 in existing system)

163:

short (Int16, 16 bit integer)

164:

ushort (UInt16, unsigned short)

323:

int (Int32, 32 bit integer, default)

324:

uint (UInt32, unsigned int)

325:

float (Single, 32 bit real)

643:

long (Int64, 64 bit integer)

644:

ulong (UInt64, unsigned long)

645:

double (Double, 64 bit real, default)

1285:

Decimal (128 bit real)

807:

object (serialized object)

99999:

no code available for data type

 

Example:

      ⎕dr 10

323

      dr 10L

643

      dr 20.1

645

      dr 10f

325

 

Dyadic:

The left argument to ⎕dr can be a legacy code listed above.  When this is the case the data on the right is coerced to the new data type based on the bit representation of the data.

Example:

Converts a short to a Boolean representation:

      11 ⎕dr (short)32

0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0

 

      323 ⎕dr 10.1

858993459 1076114227

 

      645 ⎕dr 323 ⎕dr 10.1

10.1

 

      645 ⎕dr (bool) 11 ⎕dr 10.1

10.1

 

 

Note

Requirement for casting to Boolean as the result of 11 ⎕dr 10.1 is an integer array of 1 and 0.

Often what is desired is to cast an int to a double, a double to an int, a short to and int, etc.

Using a type as the left argument to ⎕dr accomplishes this.

 

Example:

      int dr 10.1

10

      int ⎕dr 10.1 10.6

10 11

      ⎕dr double ⎕dr 10

645

 

It is also possible to serialize data using dr.  This is accomplished using the text string "wrapl" as the left argument.  To deserialize the data, use "unwrapl"

      a = "wrapl" ⎕dr 10 "test" 20

      b = "wrapl" ⎕dr 10 "test" 20

 

The result of the serialization is a string and the result is always identical for identical data.  This means that the results can be compared for the purposes of checking equivalence.

Any object that supports serialization can be serialized either individually or as part of a nested structure.

If you understand the serialization of the object, you can even modify the string which will impact the object that you return. 

This is useful for sending objects either over the internet or writing and object to file and then retrieving and reinstantiating the object at a later time.