Files
mdk_01.04_teslenko/lab2/README.md
T

44 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ОТЧЕТ О РАБОТЕ
# Отчет по практическому заданию №2
* **Студент:** Тесленко Анастасия и Грищенко Екатерина
* **Группа:** 228
---
* **Цель работы:** Понять, как разные типы данных представляются в памяти на уровне битов, научиться "читать" числа с плавающей точкой, разобраться с переполнениями целых чисел и понять одну из самых коварных особенностей C/C++ — strict aliasing.
---
# Ход работы:
*Задание 1*
Основнвой код:
```C
#include <stdio.h>
#include <stdint.h>
#include <string.h>
union FloatCvrt{
uint32_t raw_bits;
float value;
};
float makeFloat(uint32_t sign, uint8_t exp, uint32_t mantissa){
union FloatCvrt converter;
converter.raw_bits = ((sign & 0x1) << 31) | (((uint32_t)exp & 0xFF) << 23) | (mantissa & 0x7FFFFF);
return converter.value;
};
int main(){
float f1 = makeFloat(0,127,0);
printf("Custom 1.0f = %f\n", f1);
float f2 = makeFloat(1,128,0x200000);
printf("Custom -2.5f = %f\n", f2);
return 0;
};
```