Char: ConvertToInt32

ConvertToInt32

Converts the character value to a 32-bit signed integer.



 Public Function ConvertToInt32(
	  ByVal c As Integer ) As Long

Parameters

c
[ByVal] Integer. The character to be converted.

Return Values

Long -  A 32-bit signed integer representing the numeric value of the character.

Remarks

In VBCorLib characters are represented with 16-bit signed integers. In order to represent all characters, the numeric value may be represented with a negative value.

If the numeric value is negative, converted positive value will have the same 16-bit binary representation.

A character value of -1(&HFFFF) is converted to 65535(&HFFFF&). Both values have the same 16-bit binary representation.

The converted value will represent a value that can be correctly used for sort order. If characters need to be compared for sorting, consider using Char.Compare to make comparisons.

Examples

This example demonstrates converting a character represented as a 16-bit signed integer to a positive 32-bit signed integer using the ConvertToInt32 method.

Public Sub Main()
    Convert 65
    Convert -1
    Convert -32768
    Convert 32767
End Sub

Private Sub Convert(ByVal c As Integer)
    Dim Ch As Long
    
    Ch = Char.ConvertToInt32(c)
    
    Debug.Print CorString.Format("{0,6}(&h{0:X4}) converts to {1,6}(&h{1:X8})", c, Ch)
End Sub

' The example code produces the following output.
'
'        65(&h0041) converts to     65(&h00000041)
'        -1(&hFFFF) converts to  65535(&h0000FFFF)
'    -32768(&h8000) converts to  32768(&h00008000)
'     32767(&h7FFF) converts to  32767(&h00007FFF)

See Also

Project CorLib Overview

Class Char Overview

ConvertFromInt32

Compare

Equals