-=:: FBSL ::=-

(C)2001-2010 by Gerome GUILLEMIN, Mehdi BOUAZIZ and Mike LOBANOVSKY
It is currently Thu Sep 09, 2010 12:30 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: endian order conversions
PostPosted: Thu Nov 12, 2009 6:48 pm 
Offline
FBSL Administrator
FBSL Administrator
User avatar

Joined: Sat Nov 24, 2007 3:33 pm
Posts: 316
Location: France
i was googleing and i found this interesting to convert :

Code:
// This code converts big Endian to little Endian and vice-versa

// similar code for float and int as well.

float swapEndianInt( float bEnum )
{

float lEnum;
char *lE = (char*) &lEnum;
char *bE = (char*) &bEnum;
lE[0] = bE[3];
lE[1] = bE[2];
lE[2] = bE[1];
lE[3] = bE[0];
return lEnum;

}


is there any way to achieve this quickly in fbsl ? perhaps using getmem or bitshifting operators ?

_________________
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows Vista Home Premium Fr)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 12, 2009 8:21 pm 
Offline
FBSL Administrator
FBSL Administrator
User avatar

Joined: Sat Nov 24, 2007 3:33 pm
Posts: 316
Location: France
ok here is a simple asm convertion :
Code:
apptype console

Dim %v
v= &H01020304
? v
? Hex(v)

swapEndian(@v)

? Hex(v)
Pause


Asm swapEndian(buffer As Integer)
#Define buffer dword ptr[ebp + 8] ' Buffer pointer

enter 0, 0
mov edx, buffer ' Point edx to buffer
mov ebx, 4

'first swap R and A
   mov al,[edx]            ' Load value at edx into al
   mov ah,[edx+3]            ' Load value at edx+3 into ah
   mov [edx+3],al            ' Store value in al at edx+3
   mov [edx],ah            ' Store value in ah at edx

'then Swap G and B
   mov al,[edx+1]            ' Load value at edx+1 into al
   mov ah,[edx+2]            ' Load value at edx+2 into ah
   mov [edx+2],al            ' Store value in al at edx+2
   mov [edx+1],ah            ' Store value in ah at edx+1

#Undef buffer
   leave
   ret
End Asm


_________________
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows Vista Home Premium Fr)


Top
 Profile  
 
 Post subject: Re: endian order conversions
PostPosted: Thu Nov 12, 2009 9:05 pm 
Offline
FBSL Administrator
FBSL Administrator
User avatar

Joined: Sat Mar 12, 2005 8:06 pm
Posts: 2877
Location: Paris -- France
Codeman wrote:
i was googleing and i found this interesting to convert :

Code:
// This code converts big Endian to little Endian and vice-versa

// similar code for float and int as well.

float swapEndianInt( float bEnum )
{

float lEnum;
char *lE = (char*) &lEnum;
char *bE = (char*) &bEnum;
lE[0] = bE[3];
lE[1] = bE[2];
lE[2] = bE[1];
lE[3] = bE[0];
return lEnum;

}


is there any way to achieve this quickly in fbsl ? perhaps using getmem or bitshifting operators ?


This function can be easily added to the core FBSL grammar !

_________________
Yours,

(¯`·._.·[Gerome GUILLEMIN]·._.·´¯)
:: Full SETUP w. HELP 07th of September 2010 ::
http://gedd123.free.fr/FBSLv3.exe [3.4.0.7]
http://gedd123.free.fr/FBSLv3bin.zip [minimal]
Laissons les jolies femmes aux hommes sans imagination. / Let us leave pretty women to men without imagination.(M.Proust)
The success is a defeat for the one who does not want to dance any more! (H.F. Thiefaine)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 12, 2009 10:31 pm 
Offline
FBSL Administrator
FBSL Administrator
User avatar

Joined: Sat Nov 24, 2007 3:33 pm
Posts: 316
Location: France
YES I THINK IT CAN BE USEFULL IN SOME CASES :D

(sorry for uppercase )

_________________
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows Vista Home Premium Fr)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 13, 2009 3:23 pm 
Offline
FBSL Administrator
FBSL Administrator
User avatar

Joined: Sat Nov 24, 2007 3:33 pm
Posts: 316
Location: France
another version using peek and poke:
Code:
Sub endianswap(vin,vout)
Poke(@vout+3,$Peek(@vin,$1))
Poke(@vout+2,$Peek(@vin+1,$1))
Poke(@vout+1,$Peek(@vin+2,$1))
Poke(@vout,$Peek(@vin+3,$1))
End Sub


_________________
_-=<(¯`·._.·[ CodeMan ]·._.·´¯)>=-_
Your only limit : Your imagination

FBSL V3 TESTED On :
Image

Chris (2.0GHz AMD Atlon 64 X2 3800+ w/ 4GB RAM, GeForce 9600GT w/ 1GB VRAM, Windows Vista Home Premium Fr)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group