本文介绍了这是否$ C的大小尾$ C检?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我小尾数听说后,LSB是在起始地址和大端MSB为起始地址。所以我写了我的code这样。如果不是,为什么?

 无效checkEndianess()
{INT I = 1;
焦C =(char)的我;如果(C)
        COUT<<小Endian<< ENDL;
其他
    COUT<<大端<< ENDL;
}


解决方案

没有,你正在做一个int,并且它转换为一个char,这是一个高层次的概念(和将在内部最有可能在寄存器中完成)。具有无关端标记,这是主要涉及存储器的概念。

您可能正在寻找这样的:

  INT I = 1;
字符C = *(字符*)及我;如果(C){
   COUT<< 小尾数<< ENDL;
}其他{
   COUT<< 大端<< ENDL;
}

I heard in little endian, the LSB is at starting address and in Big endian MSB is at starting address. SO I wrote my code like this. If not why ?

void checkEndianess()
{

int i = 1;
char c = (char)i;

if(c)
        cout<<"Little Endian"<<endl;
else
    cout<<"Big Endian"<<endl;


}
解决方案

No, you're taking an int and are casting it to a char, which is a high-level concept (and will internally most likely be done in registers). That has nothing to do with endianness, which is a concept that mostly pertains to memory.

You're probably looking for this:

int i = 1;
char c = *(char *) &i;

if (c) {
   cout << "Little endian" << endl;
} else {
   cout << "Big endian" << endl;
}

这篇关于这是否$ C的大小尾$ C检?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 10:18