小编Ben*_*min的帖子

如何在C++中将16位十六进制颜色转换为RGB888值

我有uint16_t color并且需要将其转换为RGB等效物.设置十六进制使前5位代表红色,接下来6代表绿色,最后5代表蓝色.

到目前为止,我已经发现了一些接近解决方案的东西,但并不是因为截断.

void hexToRGB(uint16_t hexValue)
{

    int r = ((hexValue >> 11) & 0x1F);  // Extract the 5 R bits
    int g = ((hexValue >> 5) & 0x3F);   // Extract the 6 G bits
    int b = ((hexValue) & 0x1F);        // Extract the 5 B bits

    r = ((r * 255) / 31) - 4;
    g = ((g * 255) / 63) - 2;
    b = ((b * 255) / 31) - 4;

    printf("r: %d, g: %d, …
Run Code Online (Sandbox Code Playgroud)

c++ colors

3
推荐指数
2
解决办法
3814
查看次数

如何仅替换匹配集合中的特定匹配?

我正在写一个求解方程的求解方法.该方法将是递归的; 搜索所有外括号并在找到时调用求解括号内的值,并在未找到括号时返回该值.

这个过程应该是这样的

20 * (6+3) / ((4+6)*9)
20 * 9 / ((4+6)*9)
20 * 9 / (10*9)
20 * 9 / 90
2
Run Code Online (Sandbox Code Playgroud)

如您所见,每场比赛可能有不同的替换值.我需要将括号替换为它的计算结果.有没有办法做到这一点.这是我到目前为止所拥有的.

public int solve(string etq)
    {

        Regex rgx = new Regex(@"\(([^()]|(?R))*\)");
        MatchCollection matches;

        matches = rgx.Matches(etq);

        foreach(Match m in matches){

            //replace m in etq with unique value here

        }

    //calculations here
    return calculation
    }
Run Code Online (Sandbox Code Playgroud)

Regex.replace(...)替换所有出现的指定模式.我希望能够匹配多个场景并用不同的输出替换每个场景

c# regex string

2
推荐指数
1
解决办法
1554
查看次数

标签 统计

c# ×1

c++ ×1

colors ×1

regex ×1

string ×1