# inttypes

***

**1. Converting Signed Integer to String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  int64_t num = -123456789;
  char buffer[32];
  sprintf(buffer, "%" PRIi64, num);
  printf("Signed integer as a string: %s\n", buffer);
  return 0;
}
```

**2. Converting Unsigned Integer to String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  uint64_t num = 123456789;
  char buffer[32];
  sprintf(buffer, "%" PRIu64, num);
  printf("Unsigned integer as a string: %s\n", buffer);
  return 0;
}
```

**3. Reading Signed Integer from String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  char *str = "-123456789";
  int64_t num;
  sscanf(str, "%" SCNi64, &num);
  printf("Signed integer from a string: %" PRIi64 "\n", num);
  return 0;
}
```

**4. Reading Unsigned Integer from String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  char *str = "123456789";
  uint64_t num;
  sscanf(str, "%" SCNu64, &num);
  printf("Unsigned integer from a string: %" PRIu64 "\n", num);
  return 0;
}
```

**5. Maximum and Minimum Values of Integer Types**

```c++
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>

int main() {
  printf("Maximum value of int64_t: %" PRIi64 "\n", INT64_MAX);
  printf("Minimum value of int64_t: %" PRIi64 "\n", INT64_MIN);
  return 0;
}
```

**6. Size of Integer Types**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  printf("Size of int64_t: %zu bytes\n", sizeof(int64_t));
  printf("Size of uint64_t: %zu bytes\n", sizeof(uint64_t));
  return 0;
}
```

**7. Formatting Signed Integer with Commas**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  int64_t num = 123456789;
  printf("Signed integer with commas: %" PRIi64 ",\n", num);
  return 0;
}
```

**8. Formatting Unsigned Integer with Commas**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  uint64_t num = 123456789;
  printf("Unsigned integer with commas: %" PRIu64 ",\n", num);
  return 0;
}
```

**9. Reading Fixed-Width Integer from File**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  FILE *fp = fopen("data.txt", "r");
  int64_t num;
  fscanf(fp, "%" SCNd64, &num);
  fclose(fp);
  printf("Fixed-width integer read from file: %" PRIi64 "\n", num);
  return 0;
}
```

**10. Writing Fixed-Width Integer to File**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  FILE *fp = fopen("data.txt", "w");
  int64_t num = 123456789;
  fprintf(fp, "%" PRId64, num);
  fclose(fp);
  printf("Fixed-width integer written to file.\n");
  return 0;
}
```

**11. Reading Hexadecimal Integer from String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  char *str = "0x12345678";
  uint64_t num;
  sscanf(str, "%" SCNx64, &num);
  printf("Hexadecimal integer from a string: %" PRIu64 "\n", num);
  return 0;
}
```

**12. Writing Hexadecimal Integer to String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  uint64_t num = 0x12345678;
  char buffer[32];
  sprintf(buffer, "%016" PRIx64, num);
  printf("Hexadecimal integer as a string: %s\n", buffer);
  return 0;
}
```

**13. Reading Octal Integer from String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  char *str = "01234567";
  uint64_t num;
  sscanf(str, "%" SCNo64, &num);
  printf("Octal integer from a string: %" PRIu64 "\n", num);
  return 0;
}
```

**14. Writing Octal Integer to String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  uint64_t num = 01234567;
  char buffer[32];
  sprintf(buffer, "%011" PRIo64, num);
  printf("Octal integer as a string: %s\n", buffer);
  return 0;
}
```

**15. Reading Binary Integer from String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  char *str = "11110101";
  uint64_t num;
  sscanf(str, "%" SCNu64, &num);
  printf("Binary integer from a string: %" PRIu64 "\n", num);
  return 0;
}
```

**16. Writing Binary Integer to String**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  uint64_t num = 0b11110101;
  char buffer[32];
  sprintf(buffer, "%032" PRIb64, num);
  printf("Binary integer as a string: %s\n", buffer);
  return 0;
}
```

**17. Converting Floating-Point Number to Fixed-Point Integer**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  double num = 123.456;
  int64_t fixed_point = (int64_t)(num * 10000);
  printf("Fixed-point integer: %" PRIi64 "\n", fixed_point);
  return 0;
}
```

**18. Converting Fixed-Point Integer to Floating-Point Number**

```c++
#include <inttypes.h>
#include <stdio.h>

int main() {
  int64_t fixed_point = 123456;
  double num = (double)fixed_point / 10000;
  printf("Floating-point number: %f\n", num);
  return 0;
}
```

**19. Saturating Arithmetic**

```c++
#include <inttypes.h>


```
