参考How do you set, clear and toggle a single bit in C? c/c++中对二进制位的操作包括设置某位为1.清除某位(置为0).开关某位(toggling a bit).检查某位是否为1等.这些操作较为常见并且可以作为其他位运算的基础接口,以下罗列几种方法: 传统方法 设置某位为1 number |= 1 << x; // 设置第x位为1 清除某位 number &= ~(1 << x); // 置第x位为0 开关某位 numb…
在日常编程过程中,我们可能经常需要Copy各种数组,一般来说有以下几种常见的方法:Array.Copy,IList<T>.Copy,BinaryReader.ReadBytes,Buffer.BlockCopy,以及System.Buffer.memcpyimpl,由于最后一种需要使用指针,所以本文不引入该方法. 本次测试,使用以上前4种方法,各运行1000万次,观察结果. using System; using System.Collections.Generic; using System…
最近在完成MySql项目集成的情况下,需要增加批量更新的功能,根据网上的资料整理了一下,很好用,都测试过,可以直接使用. mysql 批量更新共有以下四种办法 1..replace into 批量更新 replace into test_tbl (id,dr) values (1,'2'),(2,'3'),...(x,'y'); 例子:replace into book (`Id`,`Author`,`CreatedTime`,`UpdatedTime`) values (1,'张飞',…
[原文链接] 在日常编程过程中,我们可能经常需要Copy各种数组,一般来说有以下几种常见的方法:Array.Copy,IList<T>.Copy,BinaryReader.ReadBytes,Buffer.BlockCopy,以及System.Buffer.memcpyimpl,由于最后一种需要使用指针,所以本文不引入该方法. 本次测试,使用以上前4种方法,各运行1000万次,观察结果. using System; using System.Collections.Generic; using…
01.使用两个for循环实现List去重(有序) /**使用两个for循环实现List去重(有序) * * @param list * */ public static List removeDuplicationBy2For(List<Integer> list) { for (int i=0;i<list.size();i++) { for (int j=i+1;j<list.size();j++)…
To enforce the ability of an object to hide its data, the compiler limits the scope of instance variables—that is, limits their visibility within the program. 为了强制一个对象隐藏其数据,编译器限制实例变量范围以限制其在程序中的可见性 But to provide flexibility, it also lets you explicit…