Raised This Month: $32 Target: $400
 8% 

What is ~0 value?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-08-2021 , 23:18   What is ~0 value?
Reply With Quote #1

Shouldn't it be equal to ~( 1 << 32 )
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-09-2021 , 00:48   Re: What is ~0 value?
Reply With Quote #2

Shifting by more than the size of the datatype is undefined in C and C++ (which likely applies to Pawn) so it's not a valid thing to do. So, effectively, 1<<32 is an invalid operation. See here.
__________________

Last edited by fysiks; 02-09-2021 at 00:49.
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-09-2021 , 05:12   Re: What is ~0 value?
Reply With Quote #3

Thanks helped alot.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-09-2021 , 09:12   Re: What is ~0 value?
Reply With Quote #4

so i am a bit confused how do i get a value of 32 bits of 1 is it like this ?

( 31 << 31 ) ?

since ~0 is invalid but it should work, returning a 32 bits of 1
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-09-2021 at 09:26.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-09-2021 , 09:55   Re: What is ~0 value?
Reply With Quote #5

What do you mean by 32 bits of 1? What are you trying to do?

31 << 31 is something like:

31 = 0001 1111

31 shifted left 31 (I may be slightly off)
1111 1000 0000 0000 0000 0000 0000 0000 0000

Bitwise-not on 0 should flip all bits to 1
__________________

Last edited by Bugsy; 02-09-2021 at 09:57.
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-09-2021 , 12:56   Re: What is ~0 value?
Reply With Quote #6

what bit shifting will give me the following flip all of them to 1 ?
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-09-2021 , 13:05   Re: What is ~0 value?
Reply With Quote #7

Bit shifting does not flip any bits, it moves bits.

1 << 3
0000 0001 (value of 1 in bits)
to
0000 1000 (1 moved 3 positions to the left)

3 << 3
0000 0011 (value of 3 in bits)
to
0001 1000 (3 moved 3 positions to the left)

Try it
PHP Code:
new iVal = -1;
new 
szBits33 ];
    
for ( new 
31 >= i-- )
{
    
szBits31 ] = iVal & ( << ) ? '1' '0';
}
    
server_print"Bits = %s" szBits ); 
__________________
Bugsy is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 02-09-2021 , 13:42   Re: What is ~0 value?
Reply With Quote #8

so you're saying that value ( -1 ) is equal to 0xFFFFFFFF or i misunderstood ?

i already solved my issue with 0xFFFFFFFF i just want to know if -1 is the same and how ?


Quote:
Originally Posted by Bugsy View Post

Bitwise-not on 0 should flip all bits to 1
well that was unexpected fail, i tested it out and it didn't work quiet well.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 02-09-2021 at 14:51.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-09-2021 , 17:49   Re: What is ~0 value?
Reply With Quote #9

Read up on bits, there are tutorials all over the net, they are not specific to AMX-X.

What didn't work in the code I posted? It worked for me

PHP Code:
public test() 
{
    new 
iVal = ~0;
    new 
szBits40 ];
    new 
iStringPos charsmaxszBits );
    
    
szBitsiStringPos ] = EOS;
    
    for ( new 
31 >= i-- )
    {
        
szBitscharsmaxszBits ) - iStringPos-- ] = iVal & ( << ) ? '1' '0';
        
        if ( !( 
iStringPos ) && ( iStringPos ) )
            
szBitscharsmaxszBits ) - iStringPos-- ] = ' ';    
    }
    
    
server_print"Value = %d" iVal );
    
server_print"Bits = %s" szBits );

Output:
Code:
Value = -1
Bits = 1111 1111 1111 1111 1111 1111 1111 1111
__________________

Last edited by Bugsy; 02-09-2021 at 22:16.
Bugsy is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 02-09-2021 , 22:59   Re: What is ~0 value?
Reply With Quote #10

Quote:
Originally Posted by Natsheh View Post
so you're saying that value ( -1 ) is equal to 0xFFFFFFFF or i misunderstood ?
See Two's Complement.
__________________
fysiks is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode