如何从以下字节中提取日期时间?

时间:2015-12-17 21:54:18

标签: c# .net

我在附加图像中有以下5个字节,需要从中提取日期时间。我知道我需要进行位移,也许可以使用按位和#,但无法从字节中获取正确的信息。

enter image description here

2 个答案:

答案 0 :(得分:3)

也许这个?

gsub

答案 1 :(得分:1)

我最近在C#中回答了有关位移和整数打包的问题。

可能是在这种情况下编写的助手类对你来说是有用的

public static class BinaryConverter
{
    public static BitArray ToBinary(this int numeral)
    {
        return new BitArray(new[] { numeral });
    }

    public static int ToNumeral(this BitArray binary)
    {
        if (binary == null)
            throw new ArgumentNullException("binary");
        if (binary.Length > 32)
            throw new ArgumentException("must be at most 32 bits long");

        var result = new int[1];
        binary.CopyTo(result, 0);
        return result[0];
    }

    public static BitArray Take (this BitArray current, int length )
    {
        if (current.Length < length)
            throw new Exception("Invalid length parameter");

        List<bool> taken = new List<bool>();

        for (int i = 0; i < length; i++)
                taken.Add(current.Get(i));

        return new BitArray(taken.ToArray());
    }

    public static BitArray Shift (this BitArray current, int length )
    {
        if (current.Length < length)
            throw new Exception("Invalid length parameter");

        List<bool> shifted = new List<bool>();

        for (int i = 0; i < current.Length - length; i++)
            shifted.Add(current.Get(length + i));

        return new BitArray(shifted.ToArray());
    }

    public static BitArray FitSize (this BitArray current, int size)
    {
        List<bool> bools = new List<bool>() ;
        bools = bools.InitBoolArray(size);

        for (int i = 0; i < current.Count; i++)
                bools[i] = current.Get(i) ;

        return new BitArray(bools.ToArray());
    }

    public static List<bool> InitBoolArray(this List<bool> current, int size)
    {
        List<bool> bools = new List<bool> ();

        for (int i = 0; i < size; i++)
            bools.Add(false);

        return bools ;
    }

这里是对该答案的引用 Dynamic Bit Shifting / Unshifting

在上面的链接中显示了如何在同一个整数上包装小数字,你的五个字节非常接近那个问题

相关问题