相关疑难解决方法(0)

将BCD转换为二进制的最有效方法

我有下面的代码将32位BCD值(以两个uint half提供)转换为uint二进制值.

提供的值最大为0x9999,最大值为0x99999999.

是否有更好(即更快)的方法来实现这一目标?

    /// <summary>
    /// Convert two PLC words in BCD format (forming 8 digit number) into single binary integer.
    /// e.g. If Lower = 0x5678 and Upper = 0x1234, then Return is 12345678 decimal, or 0xbc614e.
    /// </summary>
    /// <param name="lower">Least significant 16 bits.</param>
    /// <param name="upper">Most significant 16 bits.</param>
    /// <returns>32 bit unsigned integer.</returns>
    /// <remarks>If the parameters supplied are invalid, returns zero.</remarks>
    private static uint BCD2ToBin(uint lower, uint upper)
    {
        uint binVal = 0;

        if …
Run Code Online (Sandbox Code Playgroud)

c# binary bcd

5
推荐指数
3
解决办法
1万
查看次数

标签 统计

bcd ×1

binary ×1

c# ×1