#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#define ROW_UNIT 512
#define UNIT_LENGTH 500
int charindex[8] = {
0x80, 0x40, 0x20, 0x10,
0x08, 0x04, 0x02, 0x01
};
static inline int strtobit(void *bit, char *str)
{
int pos = 0;
char *bits = bit;
memset(bits, 0, ROW_UNIT >> 3);
while(('0' == *str) || ('1' == *str)) {
if('1' == *str) {
bits[pos>>3] |= charindex[pos&0x7];
}
++str;
++pos;
}
return 0;
}字符串转位序
本文介绍了一种将二进制字符串转换为位集合的方法。通过使用C语言实现,该方法可以将只包含字符'0'和'1'的字符串转换为一个特定大小的位数组。该过程涉及初始化位数组、清零所有位并根据输入字符串设置相应的位。

被折叠的 条评论
为什么被折叠?



