|
Convert a binary, octal, or hexadecimal value to decimal
|
Total Hit (4074) |
The Convert class offers a few static methods that let you easily and quickly convert a binary, octal, or hexadecimal number(stored in a String) into the equivalent Byte, Short, Integer, or Long value. These are the methods in question:
«Code LangId=2»Dim b As Byte = Convert.ToByte(value, fromB
....Read More |
Rating
|
|
|
Convert a decimal value to binary, octal, or hexadecimal
|
Total Hit (6111) |
The ToString method of the Convert class lets you easily and quickly convert a decimal value into a string representation of that number to binary, octal, or hexadecimal base:
«Code LangId=2»' convert to binary
Console.WriteLine(Convert.ToString(11, 2)) ' => 1011
' convert to octal
Console.W
....Read More |
Rating
|
|
|
MK? And CV? - Convert numbers to strings and back
|
Total Hit (9898) |
The following routines convert a numeric value into a string that represents the number, and vice versa. They are useful for reading data written by QuickBasic programs, because the QuickBasic language functions that did the conversions were not ported to Visual Basic.
Points to note:
1. These
....Read More |
Rating
|
|
|
Take advantage of the new math functions
|
Total Hit (3084) |
The System.Math class exposes several static methods that let you perform many common operations. These functions replace the VB6 functions with same name, but there are a few new functions that have no direct VB6 counterpart:
Ceiling(x) returns the integer equal or higher than the argument
Floo
....Read More |
Rating
|
|
|
Any2Dec - Convert from any numeric base to decimal
|
Total Hit (2989) |
«Code LangId=2»' convert from any base to decimal
' BASE can be in the range 2-36
Function Any2Dec(ByVal otherBaseNumber As String, ByVal base As Integer) As Long
Dim digits As String
Dim digitValue As Long
' check base
If base < 2 Or base > 36 Then
Throw New Argum
....Read More |
Rating
|
|
|
Bin - Convert from decimal to binary
|
Total Hit (3836) |
«Code LangId=2»' convert from decimal to binary
' if you pass the Digits argument, the result is truncated to that number of
' digits
'
' you should always specify Digits if passing negative values
Function Bin(ByVal value As Long, Optional ByVal digits As Short = -1) As String
' conver
....Read More |
Rating
|
|
|
BinToDec - Convert from binary to decimal
|
Total Hit (3771) |
«Code LangId=2»' convert from binary to decimal
Function BinToDec(ByVal value As String) As Long
' we just need a call to the Convert.ToInt64 static method
Return Convert.ToInt64(value, 2)
End Function
«/Code»
|
Rating
|
|
|
Dec2Any - Convert a decimal number to any other base
|
Total Hit (4073) |
«Code LangId=2»' convert a positive number to any base
' BASE can be in the range 2-36
Function Dec2Any(ByVal number As Long, ByVal base As Short) As String
Dim index As Integer
Dim digitValue As Integer
Dim res As New System.Text.StringBuilder()
Const digits As String = "0
....Read More |
Rating
|
|
|
EvaluateModule - a module for evaluating expressions
|
Total Hit (2673) |
«Code LangId=2»' A module for evaluating expressions, with support for
' parenthesis and many math functions
' Example:
' Dim expr As String = "(SQR(9)^3)+COS(0)*3+ABS(-10)"
' txtResult.Text = Evaluate(expr).ToString ' ==> 27+3+10 ==> 40
Imports System.Text.RegularExpressions
M
....Read More |
Rating
|
|
|
Hex - Convert from decimal to hexadecimal
|
Total Hit (3993) |
«Code LangId=2»' convert from decimal to hexadecimal
' if you pass the Digits argument, the result is truncated to that number of
' digits
'
' you should always specify Digits if passing negative values
Function Hex(ByVal value As Long, Optional ByVal digits As Short = -1) As String
' c
....Read More |
Rating
|
|
|
Hex2Dec - Convert from hexadecimal to decimal
|
Total Hit (8378) |
«Code LangId=2»' convert from hexadecimal to decimal
Function HexToDec(ByVal value As String) As Long
' we just need a call to the Convert.ToInt64 static method
Return Convert.ToInt64(value, 16)
End Function
«/Code»
|
Rating
|
|