本邮件内容由第三方提供,如果您不想继续收到该邮件,可 点此退订 。
Matlab实现二进制矩阵转换为十进制 - DM张朋飞 阅读原文»
一.问题描述
[1 1 1 0 1
0 1 1 0 1
0 0 1 1 0]
每两位3转换为一个十进制数,共5列,那么转换后是ceil(5/3)=2列。
[7 1
6 1
1 2]
二.问题分析
1.每八个字符划分为一个十进制,nwords=ceil(size(b,2)/8)
2.按列处理每行的字符,只不过1到8是一组,为第一列;9到17是二组,为第2列。
cb = zeros(,'uint8')
for(j=1:size(b,2))
{
w = ceil(j/8);
//用bitset(A,bit,Value),bit没组都是1到8
cb(:,w) = bitset(cb(:,w),mod(j-1,8)+1,b(:,j))
}
三.实现
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function cb = compactbit(b)
%
% b = bits array
% cb = compacted string of bits (using words of 'word' bits)
[nSamples nbits] = size(b);
nwords = ceil(nbits/8);%向上取整(正无穷方向)压缩bit->word.
cb = zeros([nSamples nwords], 'uint8');
for j = 1:nbits
w = ceil(j/8);
cb(:,w) = bitset(cb(:,w), mod(j-1,8)+1, b(:,j));
end
function cb = compactbit(b)
%
% b = bits array
% cb = compacted string of bits (using words of 'word' bits)
[nSamples nbits] = size(b);
nwords = ceil(nbits/8);%向上取整(正无穷方向)压缩bit->word.
cb = zeros([nSamples nwords], 'uint8');
for j = 1:nbits
w = ceil(j/8);
cb(:,w) = bitset(cb(:,w), mod(j-1,8)+1, b(:,j));
end
本文链接:Matlab实现二进制矩阵转换为十进制,转载请注明。
linq分页扩展 - 漫漫洒洒 阅读原文»
直接上代码了
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, int>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T,int>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IEnumerable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector)
{
var itemList = allItems.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T,int>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, bool>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, string>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
public static List<T> ToPagedList<T>(this IQueryable<T> allItems, int pageIndex, int pageSize, Expression<Func<T, DateTime>> keySelector)
{
var itemList = allItems.OrderBy(keySelector).Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
return itemList;
}
本文链接:linq分页扩展,转载请注明。
没有评论:
发表评论