An open API service indexing awesome lists of open source software.

https://github.com/aftersol/convendian

C Library for converting endianness
https://github.com/aftersol/convendian

c endian endianess endianness

Last synced: about 2 months ago
JSON representation

C Library for converting endianness

Awesome Lists containing this project

README

          

# Endian Conversion Library

A library for converting between endianness that doesn't depend on external libraries.

Place ```conv_endian.c``` and ```conv_endian.h``` into your source files

The library can be optionally be built by calling make or using CMake

## Downloads

[You can download the source code for the library here: https://github.com/Aftersol/convEndian/releases](https://github.com/Aftersol/convEndian/releases)

---

## Examples

### Reading big endian data

```c
//...

// receive data

char yourBuffer[512];
int* ptr_to_buffer = (int*)yourBuffer;
int value;

// read big endian
fread(yourBuffer, sizeof(int), 1, yourfile);

value = *ptr_to_buffer;

// to be converted and store in whatever endian your machine runs on
value = read_be_u32(value);

//...

```

### Writing big endian data

```c
//...

// write or send data

// to be converted into big endian value
int value = 1234567890;
value = convert_to_be_u32(value);

// write big endian integer
fwrite(&value, sizeof(int), 1, yourfile);

//...
```