项目日志:Day3 --- 2020.7.24

上午

做了一下冲床屏幕的界面;
试验了一下浮点数的显示情况,貌似可以直接将浮点数传到屏幕显示;

下午

数据问题;
若要显示正确的浮点数,则需要传送该浮点数的十六进制表示;
但是在C语言中浮点数不支持位操作,无法通过位运算来读出其十六进制;

通过代码解决了这个问题;
注意到在keilchar类型是表示成十六进制的,而且可以用int类型表示其数值;
所以可以先按位取出01,再通过每8位转成int型赋值给char值;
最后四个char值即可还原浮点数的16进制;

下面是代码:

#include <stdio.h>

unsigned int ans;

unsigned int buf1[32];
unsigned char buf2[4];

void Turn_16(float h)
{
    unsigned int ux, a, temp1 = 1;
    int i;

    ans = 0;
    ux = *(unsigned int *)&h;
    for (i = 31; i >= 0; i--)
    {
        a = (ux & (temp1 << i)) >> i;
        buf1[31 - i] = a;
    }

    int j = 0;
    ans += buf1[0];
    for (i = 1; i <= 32; i++)
    {
        while (i % 8 == 0)
        {
            buf2[j] = ans;
            ans = 0;
            j++;
            break;
        }
        ans *= 2;
        ans += buf1[i];
    }
}

int main()
{
    float h = 3.6;
    int i;
    Turn_16(h);
    char a, b, c, d;
    a = buf2[0];
    b = buf2[1];
    c = buf2[2];
    d = buf2[3];
    for(i = 0; i < 32; i++) {
        printf("%d ", buf1[i]);
    }
    printf("\n");

    printf("%d %d %d %d\n", a, b, c, d);
    return 0;
}

3.6 的浮点表示为:0x40666666;
代码运行结果:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
优化下面代码.bg { width: 100%; height: 100vh; background-image: url('../../assets/img/info-bg.png'); background-size: 100% 100%; background-repeat: no-repeat; position: relative; font-family: AlibabaPuHuiTiR; .goBack { position: absolute; top: 34px; right: 65px; cursor: pointer; color: #ffffff; width: 181px; padding: 15px 10px; background: rgba(24, 31, 30, 0.52); border: 1px solid #4a524e; border-radius: 5px; font-size: 18px; font-family: AlibabaPuHuiTiR; z-index: 111; display: flex; flex-direction: row; justify-content: space-between; align-items: center; } .home-left { position: absolute; top: 18%; left: 40px; width: 41%; height: 76%; font-size: 24px; color: #ffffff; } .unit { font-size: 24px; color: #636363; } .home-left-title { font-size: 24px; color: #ffffff; line-height: 36px; } .home-right { position: absolute; top: 18%; right: 88px; width: 46%; height: 78%; } .model { display: flex; justify-content: center; align-items: center; height: 90%; } #threeContained { width: 100%; height: 100%; } .model-qk-img { width: 82%; height: 90%; background-image: url('../../assets/img/howo.png'); background-size: 100% 100%; background-repeat: no-repeat; } .model-zk-img { width: 56%; height: 90%; background-image: url('../../assets/img/heavyT.png'); background-size: 100% 100%; background-repeat: no-repeat; } .model-gj-img { width: 82%; height: 90%; background-image: url('../../assets/img/transit.png'); background-size: 100% 100%; background-repeat: no-repeat; } .car-online { margin-bottom: 50px; } } .day-data { display: flex; flex-direction: row; justify-content: space-between; align-items: center; height: 29%; margin-left: 30px; } .day-val { width: 40%; } .prefix { display: inline-block; width: 6px; height: 14px; background: #ffffff; margin-right: 20px; } .zh-title { margin-left: 30px; padding-top: 30px; font-size: 30px; font-weight: 700; text-align: left; color: #ffffff; line-height: 32px; letter-spacing: 0.3px; font-family: AlibabaPuHuiTiB; } .en-title { margin-left: 30px; font-size: 14px; font-weight: 400; text-align: left; color: #ffffff; line-height: 32px; letter-spacing: -0.91px; font-family: AlibabaPuHuiTiR; }
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值