10
henseiderv
191d

# 48 boolean variables. For real? It's clear why the class name is "GameHardActivity", this certainly is hard to maintain, understand, edit, and believe. I can understand people learning, but with 2 years of experience in programming??? And there's a matrix right in the middle!!!! USE ARRAYS, PLEASE!!!!

• 2
That's a way to get around a discussion of arrays starting with 0 or 1. ;-)
• 1
Play hard, game hard
• 2
Should use a long long and bit mask it, could hold 64 books in 1 variable :)
• 0
@hexc Well with a long he could store way more than 64

Use the MSB as indicator for 0 or 1 and use the rest as each stored value with the bitmasking the total could be 9,223,372,036,854,755,807

If this was embedded I would use a much smaller type because a long is a waste of spacd if there’s only 50something stored values, I would use just the byte type and use MSB as the above way and there would be 127 Boolean like values
• 1
@QuanticoCEO a long is made up of minimum if 64 bits is it not? If you use a bit mask that would let you use 1 bit per book right
• 0
There are 64 bits a total of 8 bytes

But using one bit per book is not efficient and a waste of 8 bytes which may see like nothing but it adds up in embedded.

For example
Let’s use one byte to make it easy and the concept scales

00000000 <— LSB
|
MSB

MSB Will be used to tell the state, 0 off 1 is on, in most cases this would be reversed for the MSB as typically 1 as the MSB would mean its negative number if it was a signed int but it’s unsigned for this example l

for book one being turned on would look like this
100000001
And off would be
00000001

For book 3 we can do this for on
10000011
And off would be
00000011

Book 7 would be
10000111 ON
00000111 OFF

Book 46 would be
10101110 ON
00101110 OFF

you would bit mask two parts
MSB as the state decider and the rest for which book make sense now?
• 3
@hexc but again I’m not saying your solution wouldn’t work. What I am saying it’s an inefficient use of 8bytes. Especially when the total number needed is far less than the max of the type Long.

Not bashing you in anyway but this is one of the largest issues I have found with programmers who only use higher level languages and write only application software. I think we would have a much stronger industry building better software if more programmers understood the hardware side and have been restricted as far as memory usage. Telling a high level programmer to write something for a 16bit micro with no experience in writing efficient space conscious code would be a disaster everything would be basic INTs or Chars using up full max types when many cases don’t need that much space and a smaller type will accomplish more with less.

Learning todo more with less is lost because in college nobody learns low level languages with hardware.

If my company ever becomes super successful I will open a trade school teaching people who to write software from the ground up start with hardware small micros and move up. Guarantee when they graduate they will be far more skilled than those leaving universities.

Sorry for the rant again it’s not you at all
• 1
@QuanticoCEO I see where your coming from, I was thinking of it more in the way that you could hold 64 individual bools using the long, because if you go your route, what happens if you want item 6 and 8 and 10 to be true, if I'm understanding your example above, wouldn't you only be able to store state + id for one pair each? Where as every individual bit is essentially a flag and you have to know the constant used to lookup the state before hand in my example like:

EXAMPLE_0 = 00000001b
EXAMPLE_1 = 00000010b

Where you basically treat each bit as a book giving you 8 bools per byte essentially
• 0
@hexc okay I think I see what your solution was referring to. It makes sense