Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Invert a binary number and display the string - maybe as a function

Author
Message
yoda333
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location:
Posted: 6th Aug 2017 23:17
Hello

I have a string that represents 4 octets of a subnet address and I wish to invert the 1's and 0's in the string - maybe as a function.

a$ = "11011111101001000010010111001000"

after the inversion

a$ = "00100000010110111101101000110111"

Cheers
yoda333
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 6th Aug 2017 23:49 Edited at: 7th Aug 2017 00:06
command ReplaceString ?
or just so
AGK (Steam) V2017.07.19 : Windows 10 Pro 64 Bit : AMD (17.4.4) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Aug 2017 04:08 Edited at: 7th Aug 2017 04:08


a$ = "%11011111101001000010010111001000"

result$ = bin$( -1- val(a$) )

PlayBASIC To HTML5/WEB - Convert PlayBASIC To Machine Code
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 7th Aug 2017 07:04 Edited at: 7th Aug 2017 07:16
@Kevin Picone your advice did not work in agk 2017

as integer
Quote: "
a = %11011111101001000010010111001000

do
print(str(a))
print(str(!a)) //see Bitwise Operators
print(bin(a))
print(right("00000000000000000000000000000000"+bin(!a),32))

if GetPointerPressed() then exit

sync()
loop
end"
AGK (Steam) V2017.07.19 : Windows 10 Pro 64 Bit : AMD (17.4.4) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
yoda333
12
Years of Service
User Offline
Joined: 3rd Apr 2012
Location:
Posted: 7th Aug 2017 09:31
Hello Markus and Kevin

Thanks very much for the reply's to my question.

Markus's code snippet will suffice.


All the best
yoda333

Login to post a reply

Server time is: 2024-09-30 05:39:21
Your offset time is: 2024-09-30 05:39:21