Simple Big Endian / Little Endian byte order swap function.

Share your advanced PureBasic knowledge/code with the community.
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Simple Big Endian / Little Endian byte order swap function.

Post by DoubleDutch »

This needs to be updated for the new C compiler.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
jacdelad
Addict
Addict
Posts: 1473
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Simple Big Endian / Little Endian byte order swap function.

Post by jacdelad »

The functions provided here are used in Thorsten1867's PurePDF module (http://forums.purebasic.com/german/view ... 7f#p343706). Unfortunately this makes it impossible to use it with the new C compiler. Is there an update to this?
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
HeX0R
Addict
Addict
Posts: 992
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Simple Big Endian / Little Endian byte order swap function.

Post by HeX0R »

You can also use something simple like that:

Code: Select all

Structure _SL_
	b.a[4]
EndStructure

Procedure _SwapLong(*l._SL_)
	Swap *l\b[0], *l\b[3]
	Swap *l\b[1], *l\b[2]
EndProcedure

Procedure _SwapWord(*w._SL_)
	Swap *w\b[0], *w\b[1]
EndProcedure

a = $10203040
_SwapLong(@a)
Debug Hex(a, #PB_Long)
User avatar
mk-soft
Always Here
Always Here
Posts: 5389
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Simple Big Endian / Little Endian byte order swap function.

Post by mk-soft »

See link bswap32
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
jacdelad
Addict
Addict
Posts: 1473
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Simple Big Endian / Little Endian byte order swap function.

Post by jacdelad »

Ah great, thanks both of you!
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
AZJIO
Addict
Addict
Posts: 1358
Joined: Sun May 14, 2017 1:48 am

Re: Simple Big Endian / Little Endian byte order swap function.

Post by AZJIO »

Rescator wrote: Thu Mar 24, 2005 8:30 am if you need to convert to/from RGB,BGR

Code: Select all

c=$1199FF
Debug Hex(c)
c=((c & $00FF00) | ((c & $0000FF) << 16) | ((c & $FF0000) >> 16))
Debug Hex(c)
Post Reply