ascii.cpp

来自「非常好用的五子棋游戏源码」· C++ 代码 · 共 53 行

CPP
53
字号
// Created:11-18-98
// By Jeff Connelly

// ASCII Encoding

// ASCII characters are 7-bits in length, but a byte contains 8 bits.  There
// is an extra bit that can be used to store information.

// We read all bits, and collapse them together removing the extra bit.

#include "stdafx.h"
#define EXPORTING
#include "comprlib.h"

// Write the bit 'bit'
static void write_bit(bool bit)
{
    static unsigned int buffer = 0, mask = 128;
    if (bit)
        buffer |= mask;
    if ((mask >>= 1) == 0)
    {
        write_byte(buffer);
        buffer = 0;
        mask = 128;
    }
}

// Send all unsent bits
static void flush_bit_buffer()
{
    int i;
    for (i = 0; i < 7; ++i)
        write_bit(0);
}

// Read a bit and return it
static bool read_bit()
{
    static unsigned int buffer, mask = 0;
    if ((mask >>= 1) == 0)
    {
        buffer = read_byte();
        mask = 128;
    }
    return ((buffer & mask) != 0);
}


void EXPORT ascii_encode()
{
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?