我有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) 我正在写一个求解方程的求解方法.该方法将是递归的; 搜索所有外括号并在找到时调用求解括号内的值,并在未找到括号时返回该值.
这个过程应该是这样的
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(...)替换所有出现的指定模式.我希望能够匹配多个场景并用不同的输出替换每个场景