Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
Fast-Nop276811dThat's a way to get around a discussion of arrays starting with 0 or 1. ;-)
karma603211dPlay hard, game hard
Should use a long long and bit mask it, could hold 64 books in 1 variable :)
@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
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.
Let’s use one byte to make it easy and the concept scales
00000000 <— LSB
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
And off would be
For book 3 we can do this for on
And off would be
Book 7 would be
Book 46 would be
you would bit mask two parts
MSB as the state decider and the rest for which book make sense now?
@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
@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
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job