Design Pattern Examples
Overview of object-oriented design patterns
uint32_to_binary.c
Go to the documentation of this file.
1
6
7#include <stdlib.h>
8#include <stdint.h>
9#include <memory.h>
10
11#include "uint32_to_binary.h"
12
14// uint32_to_binary()
16void uint32_to_binary(uint32_t number, char* buffer, size_t bufferSize)
17{
18 if (buffer != NULL && bufferSize > 32)
19 {
20 int numBits = (sizeof(uint32_t) * 8);
21 int maxBitIndex = numBits - 1;
22 uint32_t mask = 1;
23
24 memset(buffer, 0, bufferSize);
25 if ((size_t)maxBitIndex >= bufferSize)
26 {
27 maxBitIndex = (int)(bufferSize - 1);
28 }
29 for (int bitIndex = maxBitIndex; bitIndex >= 0; bitIndex--)
30 {
31 buffer[bitIndex] = (number & mask) ? '1' : '0';
32 mask <<= 1;
33 }
34 }
35}
Declaration of the uint32_to_binary() function, that converts a 32-bit unsigned integer to a binary s...
void uint32_to_binary(uint32_t number, char *buffer, size_t bufferSize)
Function to convert a 32-bit unsigned integer into a string representation containing all 32 bits.