Send feedback on this topic.
Teradata.Client.Provider
GetBytes Method (TdNumber)
Example 



Teradata.Client.Provider Namespace > TdNumber Structure : GetBytes Method
The binary representation of this TdNumber structure is returned as an array of bytes.
Syntax
'Declaration
 
Public Function GetBytes() As Byte()
'Usage
 
Dim instance As TdNumber
Dim value() As Byte
 
value = instance.GetBytes()
public byte[] GetBytes()
public:
array<byte>^ GetBytes(); 

Return Value

The mantissa and exponent are returned as an array of bytes.
Exceptions
ExceptionDescription
The value of the TdDecimal is Null.
Remarks

Five unsigned 32 bit integers are used internally to store the mantissa of a number, and a signed 16 bit integer is used to store the exponent.

In the byte array, the data for the mantissa will begin at the 0 (zero) element, and the exponent will begin at the 21 element of the array. It will take 20 bytes to represent the mantissa, and 2 bytes for the exponent. The total number of elements in the array will be 22.

When the binary representation is generated, The decimal point will be removed, and the exponent will adjusted. After this is done, the five unsigned 32 bit integers of the mantissa and the signed 16 bit of the exponent are converted to a byte array. The least significant byte of the mantissa will appear in the first element of the array.

Example
The following example shows the output when GetBytes is called:
TdNumber original = TdNumber.Parse("9.8372646523235e+99");
 
Byte[] result = original.GetBytes();
 
//The decimal point in the mantissa is removed and the exponent is adjusted
//       98372646523235e+86
//
//The hex representation of the mantissa is 0x59782AA6D163.  This is internally represented by the
//five unsigned integers as {0x2AA6D163, 0x00005978, 0x00000000, 0x00000000, 0x00000000}
//
//The hex representation of the exponent is 0x56.
//
//result = {0x63, 0xD1, 0xA6, 0x2A, 0x78, 0x59, 0x00, 0x00, 0x00, 0x00, 
//          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
//          0x56, 0x00}
            
// This following example shows how a negative number will be represented.  Internally,
// negative numbers are stored in Two's Complement representation.
            
original = TdNumber.Parse("-4.32191e-50");
            
result = original.GetBytes();
            
// The decimal point in the mantissa is removed and the exponent is adjusted
//      -432191e-55
//
// The two's complement hex representation of the mantissa is 0xFFF967C1.  This is
// internally represented by the five unsigned integers as 
//     {0xFFF967C1, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF}
            
// The Two's Complement hex represenation of the exponent is 0xFFC9.
//
// result = {0xC1, 0x67, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
             0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
             0xC9, 0xFF}
Requirements

Target Platforms: Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2

See Also

Reference

TdNumber Structure
TdNumber Members