啦啦啦拉拉裤 2021-10-01 13:59 采纳率: 69.1%
浏览 65
已结题

C语言问题 使用位运算将浮点数乘以 2048

请问这个要怎么解决?在“PUT YOUR CODE HERE”写内容,前面内容不要改动,按照要求来写,da佬编写1下,蟹蟹大lao,可以用下面的例子来测试是否正确。

img

img

img


// Multiply a float by 2048 using bit operations only

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>

#include "floats.h"

// float_2048 is given the bits of a float f as a uint32_t
// it uses bit operations and + to calculate f * 2048
// and returns the bits of this value as a uint32_t
//
// if the result is too large to be represented as a float +inf or -inf is returned
//
// if f is +0, -0, +inf or -inf, or Nan it is returned unchanged
//
// float_2048 assumes f is not a denormal number
//
uint32_t float_2048(uint32_t f) {
    // PUT YOUR CODE HERE

    return 42;
}
  • 写回答

1条回答 默认 最新

  • qfl_sdu 2021-10-01 14:12
    关注

    1024=2的10次方,2048=2的11次方,左移1位相当于乘以2,所以左移11位就相当于乘以2048
    float a;
    a << 11;

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 10月12日
  • 已采纳回答 10月4日
  • 修改了问题 10月1日
  • 创建了问题 10月1日

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题