我是靠谱客的博主 柔弱凉面,这篇文章主要介绍6. 大尾数法或小尾数法,现在分享给大家,希望可以做个参考。

    编写一个函数,确定一台计算机采用大尾数法(big-endian)还是小尾数法(little-endian)。大小尾数问题指的是计算机存储多字节值时字节的顺序。

    程序代码如下:

    #include "stdafx.h"

    #include <iostream.h>

 

方案1:

    bool endianness()

    {

        int testNum;

        char *ptr;

 

        testNum = 1;

        ptr = (char *)&testNum;

        return (*ptr);

    }

 

方案2:

    bool endianness()

    {

        union

        {

            int theInteger;

            char singleByte;

        }endianTest;

 

        endianTest.theInteger = 1;

        return endianTest.singleByte;

    }

 

    int main()

    {

        bool a = endianness();

        if(a)

            cout << "大尾数" << endl;

        else

            cout << "小尾数" << endl;

        return 0;

    }

 

    程序的执行结果如下:

 

最后

以上就是柔弱凉面最近收集整理的关于6. 大尾数法或小尾数法的全部内容,更多相关6.内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部