91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C語言位操作源碼片段

發布時間:2020-07-15 01:15:29 來源:網絡 閱讀:217 作者:hydrangea88 欄目:編程語言

如下的代碼段是關于C語言位操作片段的代碼。

  Copyright 2011 Shao-Chuan Wang <shaochuan.wang AT gmail.com>

    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 <stdio.h>
#include <stdlib.h>

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<<offset);
  return 0;
}

{
  unsigned int offset = n % INT_NBITS;
  unsigned int idx = n / INT_NBITS;
  if (!p)
    return -1;
  b = p->b;
  b[idx] &= ~(1<<offset);

  return 0;
}

{
  int j;
  if (!p)
    return;
  b = p->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;
}
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

股票| 威信县| 临桂县| 大石桥市| 观塘区| 本溪市| 谢通门县| 突泉县| 多伦县| 诸暨市| 安远县| 巴林左旗| 阿克| 合阳县| 自贡市| 永吉县| 湘西| 江陵县| 上高县| 彭阳县| 鄱阳县| 时尚| 新兴县| 怀来县| 栾川县| 灵寿县| 休宁县| 东乡族自治县| 仁布县| 长子县| 南京市| 盐城市| 长岛县| 新乐市| 青阳县| 卢氏县| 康乐县| 贵港市| 佛冈县| 湛江市| 岳普湖县|