Ooops
January 26, 2021, 05:38:47 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email
?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Home
Forum
Help
Search
Gallery
Login
Register
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Flags by Warpy [ 1+ years ago ]
« previous
next »
Print
Pages: [
1
]
Go Down
Author
Topic: [bb] Flags by Warpy [ 1+ years ago ] (Read 425 times)
BlitzBot
Jr. Member
Posts: 1
[bb] Flags by Warpy [ 1+ years ago ]
«
on:
June 29, 2017, 12:28:39 AM »
Title :
Flags
Author :
Warpy
Posted :
1+ years ago
Description :
A bit like the deathmatch flags in the Quake games... very useful
Code :
Code: BlitzBasic
While
1
;show instructions
Print
"flag 1 - man"
Print
"flag 2 - mouse"
Print
"flag 4 - blue"
Print
"flag 8 - red"
;user input a number, which is the values of the flags selected added together, eg
num=
Input
(
"number: "
)
;check if flags are set
If
num
And
1
Then
Print
"man!"
If
num
And
2
Then
Print
"mouse!"
If
num
And
4
Then
Print
"blue!"
If
num
And
8
Then
Print
"red!"
;..repeat for as many powers of two as you want
;this works because of the way computers store numbers.
;Numbers are stored as a string of 0s and 1s, with each power of two being represented by one of the bits in the string
;eg 1 is shown as 0001 and 2 is shown as 0010
;to make numbers other than powers of two, you just add them together
;eg 3 is 0011 (2+1) and 7 is 0111 (4+2+1)
;the AND operation returns a number which is made by checking each bit in one number with the corresponding bit in another number.
;If they're both 1, Then the corresponding bit in the number returned is set To 1. Otherwise, it's set To 0
;This allows you to see whether any power of 2 is used to make a number
;and so store the values of lots of flags (True/False values) in one number
;Here, the code checks for flags 1,2,4 and 8
;So, if you entered the number 9 (1001), 9 AND 1 works like this:
;1001
;1000
;returns
;1000
;Similarly, 9 AND 1 does this:
;1001
;1000
;returns
;0001
;Very clever, no? :)
Wend
Comments :
Regular K(Posted 1+ years ago)
For this to work in BMax, instead of using "And", use "&".Flags are very useful!
n8r2k(Posted 1+ years ago)
sweet a comment after 4 years, lol
ShadowTurtle(Posted 1+ years ago)
sweet a comment after 1 week, lol
n8r2k(Posted 1+ years ago)
hmm, 1 week compared to 4 years, thats like saying 7 days compared to 1460 days, anyway, just discovered ths at bottom of forums page.
Logged
Print
Pages: [
1
]
Go Up
« previous
next »
SyntaxBomb - Indie Coders
»
Languages & Coding
»
Blitz Code Archives
»
Algorithms
»
[bb] Flags by Warpy [ 1+ years ago ]
SimplePortal 2.3.6 © 2008-2014, SimplePortal