一副扑克牌是52张
13级4套
有效的手部表现和评估

A    K    Q    J    T    9    8    7    6    5    4    3    2
scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh

52位
AS、AC、QS、QH、8S、7S、6S
A    K    Q    J    T    9    8    7    6    5    4    3    2
scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh scdh
1  1      1  1                1    1    1

它在9卡36位处断开
到最后一盘还可以
byte s = 1;

UInt16 spades4 = (UInt16)((s << 12) + (s << 8) + (s << 4) + (s & 0xff));
Debug.WriteLine("Hexadecimal value of {0} is {1} {2}", spades4, String.Format("{0:X}", spades4), Convert.ToString(spades4, 2).PadLeft(16, '0'));
Debug.WriteLine("");

UInt32 spades8 = (UInt32)((s << 28) + (s << 24) + (s << 20) + (s << 16) + (s << 12) + (s << 8) + (s << 4) + (s & 0xff));
Debug.WriteLine("Hexadecimal value of {0} is {1} {2}", spades8, String.Format("{0:X}", spades8), Convert.ToString(spades8, 2).PadLeft(32, '0'));
Debug.WriteLine("");

Int64 spades9 = (Int64)( (s << 30) + (s << 28) + (s << 24) + (s << 20) + (s << 16) + (s << 12) + (s << 8) + (s << 4) + (s & 0xff));
Debug.WriteLine("Hexadecimal value of {0} is {1} {2}", spades9, String.Format("{0:X}", spades9), Convert.ToString(spades9, 2).PadLeft(36, '0'));
Debug.WriteLine("");

// once the shift is up to 31 it breaks - it goes negative
Int64 spades9b = (Int64)((Int64)(s << 31) + (Int64)(s << 28) + (Int64)(s << 24) + (Int64)(s << 20) + (Int64)(s << 16) + (Int64)(s << 12) + (Int64)(s << 8) + (Int64)(s << 4) + (Int64)(s & 0xff));
Debug.WriteLine("Hexadecimal value of {0} is {1} {2}", spades9b, String.Format("{0:X}", spades9b), Convert.ToString(spades9b, 2).PadLeft(36, '0'));
Debug.WriteLine("");

我试过uint64和同样的问题
我想这是解决办法
不知道我该删掉留着这个
Int64 spades9b = (Int64)(((Int64)s << 44) | ((Int64)s << 40) | ((Int64)s << 36) | ((Int64)s << 32) | (Int64)(s << 28) | (Int64)(s << 24) | (Int64)(s << 20) | (Int64)(s << 16) | (Int64)(s << 12) | (Int64)(s << 8) | (Int64)(s << 4) | (Int64)(s & 0xff));
Debug.WriteLine("Hexadecimal value of {0} is {1} {2}", spades9b, String.Format("{0:X}", spades9b), Convert.ToString(spades9b, 2).PadLeft(48, '0'));

最佳答案

一定要使用uint64(包括您没有显示的s)并且…
使用|而不是+,因为它更适合按位操作。对于带符号的Int64,+可能会导致一些问题,因为最大的正数是范围的一半。
一旦你两者都做了,如果仍然有问题,发布你的新代码和输出是什么。

关于c# - 扑克手牌表示和评估,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43193276/

10-13 00:01