Just starting out? Need help? Post your questions and find answers here.
Nituvious
Addict
Posts: 1029 Joined: Sat Jul 11, 2009 4:57 am
Location: United States
Post
by Nituvious » Sat Jun 25, 2011 5:52 pm
I'm sure this a simple question but I couldn't find anything in the documents.
How can we enumerate by the power of 2 using Enumeration/EndEnumeration? Like
▓▓▓▓▓▒▒▒▒▒░░░░░
DarkDragon
Addict
Posts: 2345 Joined: Mon Jun 02, 2003 9:16 am
Location: Germany
Contact:
Post
by DarkDragon » Sat Jun 25, 2011 6:14 pm
You can't, but you can reformat those constants, so it shows you directly the bit which is set:
Code: Select all
#a = (1 << 0)
#b = (1 << 1)
#c = (1 << 2)
#d = (1 << 3)
bye,
Daniel
Demivec
Addict
Posts: 4270 Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA
Post
by Demivec » Sat Jun 25, 2011 6:36 pm
Code: Select all
Macro debugBin(var)
Debug "%" + RSet(Bin(var), 8, "0")
EndMacro
Macro nextUp
(#PB_Compiler_EnumerationValue - 1) * 2
EndMacro
Enumeration
#a = 1
#b = nextUp
#c = nextUp
#d = nextUp
EndEnumeration
debugBin(#a)
debugBin(#b)
debugBin(#c)
debugBin(#d)
kenmo
Addict
Posts: 2047 Joined: Tue Dec 23, 2003 3:54 am
Post
by kenmo » Sat Jun 25, 2011 6:58 pm
Ooh, that's a clever trick Demivec. I'll remember that for future big projects.
Nituvious
Addict
Posts: 1029 Joined: Sat Jul 11, 2009 4:57 am
Location: United States
Post
by Nituvious » Sat Jun 25, 2011 7:09 pm
That IS very clever! Wow, thanks a bunch.
▓▓▓▓▓▒▒▒▒▒░░░░░
blueb
Addict
Posts: 1116 Joined: Sat Apr 26, 2003 2:15 pm
Location: Cuernavaca, Mexico
Post
by blueb » Sun Jun 26, 2011 2:15 pm
Nituvious wrote: I'm sure this a simple question but I couldn't find anything in the documents.
How can we enumerate by the power of 2 using Enumeration/EndEnumeration?
Sounds like you just want to double the previous constant.
So wouldn't this way be the easiest method?
Code: Select all
Enumeration
; Used naming convention below because #E is already a constant.
#a1 = 1
#b1 = #a1 * 2
#c1 = #b1 * 2
#d1 = #c1 * 2
#e1 = #d1 * 2
#f1 = #e1 * 2
#h1 = #f1 * 2
#i1 = #h1 * 2
#j1 = #i1 * 2
EndEnumeration
Debug #j1
--Bob
- It was too lonely at the top.
System : PB 6.21(x64) and Win 11 Pro (x64)
Hardware: AMD Ryzen 9 5900X w/64 gigs Ram, AMD RX 6950 XT Graphics w/16gigs Mem
horst
Enthusiast
Posts: 197 Joined: Wed May 28, 2003 6:57 am
Location: Munich
Contact:
Post
by horst » Mon Jun 27, 2011 8:14 am
You can also use
bit(#a) instead of #a:
Code: Select all
Macro bit(n)
(1 << (n))
EndMacro
Enumeration : #a : #b : #c : #d : EndEnumeration
Debug bit(#c)
But I prefer to use the bit macro for the assignment:
Code: Select all
#a = bit(0) : #b = bit(1) : #c = bit(2) : #d = bit(3)
Horst.