日期:2014-05-17  浏览次数:20727 次

能把32位的2进制数据存入数据库中吗
就是把32位的2进制1100100100等东西存入int型的字段里。
我在数据库中试了。好像不行。。那怎么办

------解决方案--------------------
varchar
------解决方案--------------------
int 的类型 改为bigint 已测试 可以存进去
------解决方案--------------------
int刚好就是32位,存不进去才怪了,当然了,你用字符串"1010101"是不可能存进去的
------解决方案--------------------
32位,不正好是一个Int32嘛

C# code
using System;

class App
{
    public static Int32 _Signin;

    public static Int32 GetSignin(Byte index)
    {
        return (Byte)(_Signin >> index & 1);
    }

    public static void SetSignin(Byte index, Byte value)
    {
        if (value > 0)
        {
            _Signin = 1 << index | _Signin;
        }
        else
        {
            _Signin = ~(1 << index) & _Signin;
        }
    }

    static void Main()
    {
        for (Byte i = 0; i < 31; i++)
        {
            SetSignin(i, (Byte)(i % 2 == 0 ? 1 : 0));
        }

        for (Byte i = 0; i < 31; i++)
        {
            Console.WriteLine(GetSignin(i));
        }

        Console.ReadKey();
    }
}