From dc1ec447bdc537cb4908dce74237439a3c658203 Mon Sep 17 00:00:00 2001 From: solomov_b <62+solomov_b@noreply.localhost> Date: Wed, 25 Nov 2026 16:38:36 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20works/SysProg/=D0=9F=D0=A0=202/=D0=97=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D0=B5=201=20.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- works/SysProg/ПР 2/Задание 1 .c | 45 +++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 works/SysProg/ПР 2/Задание 1 .c diff --git a/works/SysProg/ПР 2/Задание 1 .c b/works/SysProg/ПР 2/Задание 1 .c new file mode 100644 index 0000000..79ce228 --- /dev/null +++ b/works/SysProg/ПР 2/Задание 1 .c @@ -0,0 +1,45 @@ +#include +#include +#include + +typedef struct { + uint32_t mantissa : 23; + uint32_t exp : 8; + uint32_t sign : 1; +} FloatParts; + +union CustomFloat { + float f; + uint32_t u; + FloatParts parts; +}; + +float assemble_float_bitfield(uint32_t sign, uint32_t exp, uint32_t mantissa) { + union CustomFloat cf; + cf.parts.sign = sign; + cf.parts.exp = exp; + cf.parts.mantissa = mantissa; + return cf.f; +} + +float assemble_float_portable(uint32_t sign, uint32_t exp, uint32_t mantissa) { + uint32_t bits = (sign << 31) | (exp << 23) | (mantissa & 0x7FFFFF); + + union { + uint32_t u; + float f; + } converter; + converter.u = bits; + + return converter.f; +} + +int main() { + float f1 = assemble_float_portable(0, 127, 0); + printf("Собранное число: %f\n", f1); // Выведет 1.000000 + + float f2 = assemble_float_portable(1, 128, 0); + printf("Собранное число: %f\n", f2); // Выведет -2.000000 + + return 0; +} \ No newline at end of file