标签: unsigned

C#unsigned int 96位

你能帮我实现一个代表96位无符号整数的类吗?

我称这个类为Flag96.

码:

class Flag96
{
    private object array = new uint[3];

    public Flag96(uint a1, uint a2, uint a3)
    {
        uint[] _array = (uint[])array;

        _array[0] = a1;
        _array[2] = a2;
        _array[3] = a3;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用它时:

public Flag96[] example;
Run Code Online (Sandbox Code Playgroud)

不起作用.Microsoft定义的最大整数大小为64位,因此我需要一个新类.

c# int unsigned class

-1
推荐指数
1
解决办法
1167
查看次数

C++:Bitshifting未签名的短片

我正在尝试将2个unsigned char保存到一个unsigned short中.所以我所做的就是保存第一个字符,然后将它移位到第二个字符的OR.

码:

unsigned char a = 8;
unsigned char b = 2;
unsigned short c = a;
c << 8;
c |= b;
Run Code Online (Sandbox Code Playgroud)

但我首先遇到了bithift的问题.运行此代码:

unsigned char a = 8;
unsigned short c = a;
c << 8;
cout << c;
Run Code Online (Sandbox Code Playgroud)

我希望得到2048.我甚至在这里查看:http://www.miniwebtool.com/bitwise-calculator/bit-shift/?data_type = 10&number = 8&place = 8 &operator = Shift + Left .但相反,我得到8.我做错了什么?

c++ unsigned short

-1
推荐指数
1
解决办法
845
查看次数

Delphi:向TFileTime添加常量

我是Delphi的新手,我需要在项目中向TFileTime添加一些常数,该常数记录了64位值的上下部分。如何在Delphi中做到这一点?我只在C ++中找到代码,但是我不知道在Delphi中如何使unsigned int64(ULONGLONG)生成,而且我也不知道如何将其转换为longword(DWORD):

ULONGLONG qwResult;

// Copy the time into a quadword.
qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime;

// Add constant
qwResult += constant;

// Copy the result back into the FILETIME structure.
ft.dwLowDateTime  = (DWORD) (qwResult & 0xFFFFFFFF );
ft.dwHighDateTime = (DWORD) (qwResult >> 32 );
Run Code Online (Sandbox Code Playgroud)

谢谢

delphi unsigned casting int64

-1
推荐指数
1
解决办法
606
查看次数

Unsigned Int 的最大值是 -1

我试图找出无符号数据类型的最小值和最大值。我知道最小无符号值是 0,最大值是 (2^n)-1。但是,当我尝试运行我的程序时(我无法发布我的代码,但您可以参考),我一直将 -1 作为最大值。有人可以向我解释为什么吗?另外,UINT_MAX 给我 4294967295,而 ULLONG_MAX 是 4294967295。但是,unsigned int 的最大值应该是 65535,而 unsigned long long int 应该是 +18,446,744,073,709,551,615。为什么输出不同?

c unsigned types unsigned-long-long-int unsigned-integer

-1
推荐指数
1
解决办法
3098
查看次数

printf 如何知道变量传递的是有符号还是无符号

鉴于以下代码片段:

signed   char x = 150;
unsigned char y = 150;
printf("%d %d\n", x, y);
Run Code Online (Sandbox Code Playgroud)

输出是:

-106 150
Run Code Online (Sandbox Code Playgroud)

但是,对于以相同方式在内存中表示的变量,我使用了相同的格式说明符。printf 如何知道它是有符号的还是无符号的。

两种情况下的内存表示为:

10010110
Run Code Online (Sandbox Code Playgroud)

c printf unsigned signed

-1
推荐指数
1
解决办法
345
查看次数

通过 C 中的按位表示比较 2 个浮点数

我考试时遇到了这个问题,但我无法真正解决它,希望得到一些帮助。

仅填充空白,当且仅当 x<y 时函数必须返回 true。假设 x,y 不能为 NaN(但可以为 +-inf),不允许进行转换,仅使用 ux, uy, sx, sy

bool func(float x, float y) {
    unsigned* uxp = ______________ ;
    unsigned* uyp = ______________ ;
    unsigned  ux  = *uxp;
    unsigned  uy  = *uyp;
    unsigned  sx = (ux>>31); 
    unsigned  sy = (uy>>31);
    return ___________________________;
}
Run Code Online (Sandbox Code Playgroud)

c floating-point unsigned bit-manipulation ieee

-1
推荐指数
1
解决办法
207
查看次数

unsigned int的最大值?

我写了一个程序来找到使用类型的最后一个Fibonacci数unsigned int.它是1836311903,但我认为最大值为unsigned intIS 65535.发生什么了?

while(true)
    {
        sequence[j] = sequence[j-1] + sequence[j-2];
        if(sequence[j-1]>sequence[j]) break;
        j++;
    }

    printf("%d", sequence[j-2]);
Run Code Online (Sandbox Code Playgroud)

c++ math int unsigned

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

C++:将unsigned long long转换为unsigned long

我试图将unsigned long long转换为unsigned long.以下是正确的方法吗?

unsigned long removeExtraBits2(unsigned long long c) {
    return (unsigned long) ((c << 32) >> 32);
}
Run Code Online (Sandbox Code Playgroud)

如果没有,你能提供一个有效的例子吗?

我的假设是,当向左移动,然后向右移动时,最左边的32位被设置为0.

谢谢!

编辑:转换的目的是摆脱额外的位,"高于"32位,有效地保持最右边的32位为无符号长.

c++ unsigned

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

为什么1ul << 64返回1而不是0?

考虑以下代码:

// Simply loop over until 64 is hit. 
unsigned long x = 0;
for (int i = 0; i <= 64; i++) {
  if (i == 64) {
    x = 1ul << i;
    printf("x: %d\n", x);
  }
}
Run Code Online (Sandbox Code Playgroud)

我们知道无符号长是64位宽,左移1到64位将变为1000 ... 000(后面有64个零),并且会被截断为0.但是,实际的打印输出给出:

x: 1
Run Code Online (Sandbox Code Playgroud)

奇怪的是,如果我们这样做的话

printf("x: %d\n", (1ul << 64));
Run Code Online (Sandbox Code Playgroud)

它会打印0.

任何人都可以解释为什么会这样吗?为什么在第一种情况下,程序错误地产生1而不是0,但在第二种情况下它是正确的?

c math unsigned gcc long-integer

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

C:unsigned int上的模运算符给出了意外的输出

#include <stdio.h>

main() {
    unsigned a = -20;
    unsigned b = 10;
    printf("%d\n", (a % b));
    printf("%d\n", (-20 % 10));
}

Output:
6
0
Run Code Online (Sandbox Code Playgroud)

第二个printf打印预期值0,而第一个printf打印6.为什么这个意外输出带有无符号整数?

c unsigned modulus unsigned-integer

-3
推荐指数
1
解决办法
1388
查看次数

有符号和无符号整数表达式[-Wsign-compare]警告之间的比较

for ( i= 0; i < sizeof(r)/sizeof(r[0]); ++i ){ 
        r[i]= 0; 
}
Run Code Online (Sandbox Code Playgroud)

所以这是for循环我遇到了麻烦,我怎么能重写它所以我没有得到警告:

comparison between signed and unsigned integer expressions [-Wsign-compare]
Run Code Online (Sandbox Code Playgroud)

c comparison unsigned warnings for-loop

-3
推荐指数
1
解决办法
1万
查看次数

C - 32位机器上的无符号长整数加倍

嗨,我有两个问题:

  1. uint64_t vs double,它覆盖正数的范围限制更高?

  2. 如果只需要double的整数部分,如何将double转换为uint64_t.

由于定义了双重,直接铸造显然不起作用.

很抱歉有任何困惑,我在谈论32位机器上的64位双C语言.

至于一个例子:

//operation for convertion I used:
double sampleRate = (
                      (union { double i; uint64_t sampleRate; })
                      { .i = r23u.outputSampleRate}
                    ).sampleRate;

//the following are printouts on command line
//         double                               uint64_t
//printed by   %.16llx                           %.16llx
outputSampleRate  0x41886a0000000000      0x41886a0000000000 sampleRate

//printed by   %f                                    %llu
outputSampleRate  51200000.000000        4722140757530509312 sampleRate
Run Code Online (Sandbox Code Playgroud)

所以这两个数字仍然是相同的位模式,但是当打印出小数时,uint64_t是完全错误的.谢谢.

c double primitive unsigned

-3
推荐指数
1
解决办法
454
查看次数

C - 是否使用unsigned int只是可怕的编码实践?

是否有任何合法使用无符号数据的例子(即unsigned int)或者应该使用无符号数据类型只是被视为非常糟糕的编码实践,作为20世纪70年代和80年代资源受损平台的遗留物?

考虑一下:

int main ()
{
    unsigned int a = 5;   /*or uint32_t if you prefer*/
    unsigned int b = 8
    unsigned int c = a - b; // I can't even store a subtraction result
                            // from my own data type!

    float f;    // ISO didn't even bother to make a signed version of float.
    double d;   // ISO didn't even bother to make a signed version of double.

    // size_t is an unsigned integer, length varies
    // …
Run Code Online (Sandbox Code Playgroud)

c unsigned

-5
推荐指数
1
解决办法
822
查看次数