整形合并、拆分、双维映射单维 map

 整形合并、拆分

void shortMerge(short high, short low, int& iM)
{
    int t = high;
    iM = (t << 16) | low;
}

void intSplit(int iM, short& high, short& low)
{
    high = iM >> 16 & 0xFFFF;
    low = iM & 0xFFFF;
}

// test
short x = 1624;
short y = 1240;
int key;
short x1, y1;
shortMerge(x, y, key);
intSplit(key, x1, y1);
std::cout << "key: " << key << "x1: " << x1 << "y1: " << y1 << std::endl;

双维映射单维 map

// map x,y -> z
short x = 1624;
short y = 1240;
short z = 5;
std::map tMap;
int key;
shortMerge(x, y, key);
tMap[key] = z;

你可能感兴趣的:(C,C++,c++)