如下的代碼段是關(guān)于C語言位操作片段的代碼。
成都創(chuàng)新互聯(lián)一直秉承“誠(chéng)信做人,踏實(shí)做事”的原則,不欺瞞客戶,是我們最起碼的底線! 以服務(wù)為基礎(chǔ),以質(zhì)量求生存,以技術(shù)求發(fā)展,成交一個(gè)客戶多一個(gè)朋友!為您提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、成都網(wǎng)頁設(shè)計(jì)、小程序定制開發(fā)、成都網(wǎng)站開發(fā)、成都網(wǎng)站制作、成都軟件開發(fā)、成都APP應(yīng)用開發(fā)是成都本地專業(yè)的網(wǎng)站建設(shè)和網(wǎng)站設(shè)計(jì)公司,等你一起來見證! Copyright 2011 Shao-Chuan Wang
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
#include
#include
typedef struct {
int size;
} packed_bits;
#define INT_MAX_BIT_MASK (1 << (INT_NBITS-1))
{
if (!b_array)
return NULL;
p = malloc(sizeof(packed_bits));
if (!p) {
free(b_array);
return NULL;
}
p->size = n_int;
p->b = b_array;
return p;
}
{
int i;
if (!p)
return -1;
b = p->b;
for (i = p->size-1;i >= 0;i--) {
b[i] = b[i] << 1;
if (i-1 >=0 && b[i-1] & INT_MAX_BIT_MASK)
b[i]++;
}
return 0;
}
{
int i;
if (!p)
return -1;
b = p->b;
for (i = 0;i < p->size;i++) {
b[i] = b[i] >> 1;
if (i+1 < p->size && (b[i+1] & 1))
b[i] |= INT_MAX_BIT_MASK;
}
return 0;
}
{
unsigned int offset = n % INT_NBITS;
unsigned int idx = n / INT_NBITS;
if (!p)
return -1;
b = p->b;
return (b[idx] & (1 << offset)) != 0;
}
{
unsigned int offset = n % INT_NBITS;
unsigned int idx = n / INT_NBITS;
if (!p)
return -1;
b = p->b;
b[idx] |= (1<b;
b[idx] &= ~(1<b;
printf("%d", read_bit(p, j));
if (j % INT_NBITS==0)
printf("n");
}
printf("n");
return;
}
{
int n_int = 4;
if (!p) {
fprintf(stderr, "Out of memory!n");
return EXIT_FAILURE;
}
set_bit(p, 1);
set_bit(p, 127);
print_bits(p);
return 0;
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。