bit swap from c to PB

Just starting out? Need help? Post your questions and find answers here.
supercdfr
User
User
Posts: 54
Joined: Tue Mar 16, 2010 9:28 pm

bit swap from c to PB

Post by supercdfr »

i have this in c :

Code: Select all

printf("%u\n\n\n",(3967115105 << 28) | (3967115105 >> 4) )
And i have the result : 516380150 that is correct

When i try whit PB, i have this :

Code: Select all

Debug (3967115105 << 28) | (3967115105 >> 4)
i have 1064914352463107574 that is incorrect.

I try stru, strd strf, but the result is always false.
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: bit swap from c to PB

Post by Shardik »

To obtain a long integer you have to remove all unwanted digits with an AND $FFFFFFFF operation. The following code line therefore displays your wanted result:

Code: Select all

Debug ((3967115105 << 28) | (3967115105 >> 4)) & $FFFFFFFF ; Displays 516380150
supercdfr
User
User
Posts: 54
Joined: Tue Mar 16, 2010 9:28 pm

Re: bit swap from c to PB

Post by supercdfr »

1000 thanks :)
User avatar
skywalk
Addict
Addict
Posts: 4221
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: bit swap from c to PB

Post by skywalk »

Code: Select all

EnableExplicit
Define.q q = (3967115105 << 28) | (3967115105 >> 4)
Define.l l = q
Debug q
Debug l
l = ((3967115105 << 28) | (3967115105 >> 4))  ;OVERFLOW; & $FFFFFFFF
;[11:35:02] [COMPILER] Line 5: Overflow error: a 'long' value (.l) must be between -2147483648 And +4294967295.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3943
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: bit swap from c to PB

Post by wilbert »

Code: Select all

l.l = 3967115105

EnableASM
ror l, 4
DisableASM

Debug l
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply