部70a3
4A3D
4093はそれを試してください:DoubleToHex
//dashseparator 0 /2/4
public string DoubleToHex(double d, bool reverse = false, int dashSeparator = 0)
{
byte[] bytes = BitConverter.GetBytes(d);
if (reverse) bytes = bytes.Reverse().ToArray();
var hex = BitConverter.ToString(bytes);
var hex4 = "";
if (dashSeparator == 2) return hex;
if (dashSeparator == 4)
{
hex = hex.Replace("-", "");
hex = Regex.Replace(hex, ".{4}", "$0-").TrimEnd('-');
return hex;
}
return hex.Replace("-", "");
}
サンプル出力:
Double: 1234.56
Hex: 0AD7A3703D4A9340
Hex in Reverse order: 40934A3D70A3D70A
Hex in Reverse order separate by 2 digits: 40-93-4A-3D-70-A3-D7-0A
Hex in Reverse order separate by 4 digits: 4093-4A3D-70A3-D70A
次のことができます。
順/逆順に表示される生成された六角-control。 0(なしセパレータ)によって
-Addダッシュセパレータ/ 2/4桁
編集:Vb.Net
にコード変換
Vb.Net版
'dashseparator 0 /2/4
Public Function DoubleToHex(d As Double, Optional reverse As Boolean = False, Optional dashseparator As Integer = 0) As String
Dim bytes As Byte() = BitConverter.GetBytes(d)
If reverse Then
Array.Reverse(bytes)
End If
Dim hex = BitConverter.ToString(bytes)
Dim hex4 = ""
If dashseparator = 2 Then
Return hex
End If
If dashseparator = 4 Then
hex = hex.Replace("-", "")
hex = Regex.Replace(hex, ".{4}", "$0-").TrimEnd("-"C)
Return hex
End If
Return hex.Replace("-", "")
End Function
何語あなたがこれを行うにしたいですか?あなたは3つの全く異なるものでそれをタグ付けしました。 – Comintern
StackOverflowでご質問ありがとうございます!これは有効な質問ですが、非常に良い質問ではありません。 'vb.net'に簡単に変換できるStackOverflow上でさえ、' C# 'でたくさんの結果を与えるべきであれば、選択した検索エンジンを使った簡単なクエリです... – ventiseis
申し訳ありません、ビジュアルベーシック。 –