`
yaojingguo
  • 浏览: 207904 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

a simple bit vector

C 
阅读更多

#include <stdio.h>

#define BYTE_LEN 8

unsigned int direct_address_search(int T[], int k) {
  int byte_offset = k / BYTE_LEN;
  int bit_offset = k % BYTE_LEN;
  return (T[byte_offset] >> bit_offset) & 1u;
}


void direct_address_insert(int T[], int k) {
  int byte_offset = k / BYTE_LEN;
  int bit_offset = k % BYTE_LEN;
  T[byte_offset] |= (1u << bit_offset);
}

void direct_address_delete(int T[], int x) {
  int byte_offset = x / BYTE_LEN;
  int bit_offset = x % BYTE_LEN;
  T[byte_offset] &= (0u << bit_offset);
}

void info(unsigned int T[], int size) {
  int i;
  for (i = 0; i < size; i++) {
    printf("%d: %#X\n", i, T[i]); 
  }
}


int main(int argc, const char *argv[]) {
  /* A 16 bit bit-vector */
  unsigned int T[2] = {0};
  direct_address_insert(T, 0);
  direct_address_insert(T, 2);
  printf("bit 1 is %d\n", direct_address_search(T, 1));
  printf("bit 2 is %d\n", direct_address_search(T, 2));
  info(T, 2);
  direct_address_delete(T, 0);
  direct_address_delete(T, 2);
  return 0;
}
 
分享到:
评论

相关推荐

    ram_dual.v

    双口RAM分伪双口RAM(Xilinx称为Simple two-dual RAM)与双口RAM(Xilinx称为true two-dual RAM),伪双口RAM,一个端口只读,另一个端口只写,且写入和读取的时钟可以不同,位宽比可以不是1:1;而双口RAM两个端口都...

    OFDM—MIMO系统的matlab程序

    ComputeSNR.m: Given the subcarrier gains, this simple function generates the SNR values of each channel (each singular value on each tone is a separate channel). chow_algo.m: Apply Chow's algorithm ...

    Advanced PDF Generator 2.0.0.0 Full Source

    Advanced PDF Generator gives you an opportunity to create PDF documents with your applications written on Delphi or C++ Builder in the most simple and easiest way. There is no need to know PDF ...

    新手上路-VHDL语言学习

    A, B, C: IN BIT; F : OUT BIT ); END simple_gate; ``` 这里的`IN`表示输入,`OUT`表示输出,`BIT`是数据类型,定义了信号的宽度为1位。 结构体则描述了模块的具体实现,包括行为、结构或数据流描述。行为描述...

    Improve the Compression Ratio by Compacting Bit-streams and Using Modified Hadamard Transform

    A modified Hadamard matrix is ... With the idea of test vector compaction, input bit-streams of the circuit under test are converted to compatible before the test set is decompose, so that a number of

    编程珠玑全部源代码 分享

    rotate.c -- Three ways to rotate the elements of a vector. The next two program are used in a pipeline to compute all anagrams in a dictionary sign.c -- Sign each word by its letters in sorted order...

    VB编程资源大全(英文控件)

    MouseHook.zip This control provides a nice, elegant way of reacting to the movement of the mouse wheel and other mouse functionality&lt;END&gt;&lt;br&gt;44,rscomm.zip Serial Comm control that provides the ...

    格雷码图片生成与保存C++实现代码

    std::vector&lt;uint8_t&gt; gray_codes = generate_gray_code(bit_depth); std::vector&lt;uint8_t&gt; pixels(width * height * 3); // RGB三通道 for (int i = 0; i (); ++i) { std::vector&lt;uint8_t&gt; rgb = gray_to_rgb...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The term Style is a bit of a misnomer, since these conventions cover far more than just source file formatting. One way in which we keep the code base manageable is by enforcing consistency. It is ...

    BobBuilder_app

    These tests were done on a HP ML120G6 system with 12Gb Ram, 10k raid disk drives running Windows 2008 Server R2 64 bit. For a measure of relative performance to RaptorDb v1 I have included a 20 ...

    simple-wireless.rar_网络_tcl/tk_

    4. **流量模型**:简单无线网络示例可能会模拟不同类型的流量,如CBR(Constant Bit Rate)用于模拟恒定比特率的应用,或UDP(User Datagram Protocol)流量用于模拟突发性数据传输。 5. **事件调度**:NS2使用事件...

    Simple and effective approach for construction of universal blind steganalyzer

    - **研究方法**:研究中提及了一类支持向量机(One-class Support Vector Machine, OC-SVM)和一类最近邻机(One-class Nearest Neighbor Machine, OC-NM)作为隐写分析中的一些技术手段。 - **关键词**:包括...

    Digital and Analogue Communication Systems 2012.

    Vector Representation, 157 Bandwidth Estimation, 160 Binary Signaling, 160 Multilevel Signaling, 162 3–5 Line Codes and Spectra 164 Binary Line Coding, 164 Power Spectra for Binary Line Codes, 167 ...

    Cisco Press - OSPF Network Design Solutions, 2nd Edition

    Contents at a Glance Introduction xix Part I OSPF Fundamentals and Communication 3 Chapter 1 Networking and...Simple Network Management Protocol 446 Introduction to SNMP 450 Network Management System 451...

    eda复习要点全 (2).docx

    - 位矢量(BIT_VECTOR) - 字符(CHARACTER) 6. **EDA设计软件**: - ALTERA公司的MAX+PLUS II和QUARTUS II - LATTICE公司的isp EXPERT SYSTEM和isp DesignExpert SYSTEM - XILINX公司的FOUNDATION和ISE 7. ...

    VC读取PNG图片并实现简单格式转换

    在VC++环境中,读取PNG...如果你需要处理MIDI文件,那将是音频处理的领域,通常会用到如MIDI库(如SMF,Simple MIDI File)等,这与图像处理是不同的技术范畴。不过,由于提供的信息不匹配,这里不再深入讨论MIDI编程。

    Bochs - The cross platform IA-32 (x86) emulator

    - USB printer: output file creation failure now causes a disconnect - re-implemented "options" parameter for additional options of connected devices (currently only used to set the speed reported ...

    amazon 云计算

    Dynamo是Amazon服务平台的基础存储架构,它支持简单的键/值方式存储数据,不支持复杂的查询,并且存储的是数据值的原始形式(bit),不解析数据的具体内容或识别任何数据结构。Dynamo的设计目标是提供一个分布式、去...

    EDA复习全讲解.pdf

    11. VHDL中常见的预定义数据类型包括布尔(BOOLEAN)、位(BIT)、位矢量(BIT_VECTOR)和字符(CHARACTER),分别在相应的库中定义,可以通过库引入来使用。 12. 数据类型的转换方法有函数转换法、类型标记转换法...

    2010秋1

    2. **网络协议**:邮件相关的协议包括SMTP(Simple Mail Transfer Protocol)、POP3(Post Office Protocol version 3)、IMAP(Internet Message Access Protocol)和HTTP(Hypertext Transfer Protocol)。...

Global site tag (gtag.js) - Google Analytics