Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bread-experts-group/byteflippers
Signed/modular types for system, big and little endian reading/writing.
https://github.com/bread-experts-group/byteflippers
ada big-endian byte endian flip little-endian lsb msb swap
Last synced: 14 days ago
JSON representation
Signed/modular types for system, big and little endian reading/writing.
- Host: GitHub
- URL: https://github.com/bread-experts-group/byteflippers
- Owner: Bread-Experts-Group
- License: apache-2.0
- Created: 2024-07-03T09:46:43.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-01-10T10:13:55.000Z (22 days ago)
- Last Synced: 2025-01-10T11:23:10.749Z (22 days ago)
- Topics: ada, big-endian, byte, endian, flip, little-endian, lsb, msb, swap
- Language: Ada
- Homepage:
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# byteflippers
[![View the Alire Crate](https://img.shields.io/endpoint?url=https://alire.ada.dev/badges/byteflippers.json)](https://alire.ada.dev/crates/byteflippers)
Modular and signed types to convert between big and little endian, such as 50 (0x00000032) to 838860800 (0x32000000). Currently supported are 16/24/[32/64/128]-bit sized signed/modular/fp numeric types for big/little endian respectively, as well as system-endian dependent base types for 8/16/24/[32/64/128]-bit signed/modular/fp numeric types (for both categories: numbers in square brackets indicate the supported sizes of floating-points (fp.)))
All types are compatible with `Interfaces` operators, such as `Shift_Left`, `Shift_Right`, `Rotate_Left`, `Rotate_Right`, as well as (where applicable) `xor`, `and`, `or`.
**NOTE:** This library depends on the GNAT compiler, as it depends on the `Provide_Shift_Operators` pragma. If you need support for another compiler, please let me know, and I'll try to support it.
## Example Use
```ada
with Byteflippers;with Ada.Text_IO;
with Ada.Streams.Stream_IO;
use Ada.Streams.Stream_IO;procedure Scratch is
package Endians_u32 renames Byteflippers.Endians_Unsigned_32;F : File_Type;
S : Stream_Access;
begin
Create (F, Name => "test.bin");
S := Stream (F);
Byteflippers.Signed_32'Write (S, 1234);
Endians_u32.Little_Endian'Write (S, 5678);
Endians_u32.Little_Endian'Write (S, 9101);
Endians_u32.Big_Endian'Write (S, 1213);
Endians_u32.Big_Endian'Write (S, 1415);Close (F);
Open (F, In_File, "test.bin");
S := Stream (F);Ada.Text_IO.Put_Line ("# System Endian Test");
Ada.Text_IO.Put_Line (Byteflippers.Signed_32'Input (S)'Image);
Ada.Text_IO.Put_Line ("# Little Endian Test (System / Little)");
Ada.Text_IO.Put_Line (Byteflippers.Signed_32'Input (S)'Image);
Ada.Text_IO.Put_Line (Endians_u32.Little_Endian'Input (S)'Image);
Ada.Text_IO.Put_Line ("# Big Endian Test (System / Big)");
Ada.Text_IO.Put_Line (Byteflippers.Signed_32'Input (S)'Image);
Ada.Text_IO.Put_Line (Endians_u32.Big_Endian'Input (S)'Image);
end Scratch;
```