ALine Posted May 5, 2021 Share Posted May 5, 2021 So the other day I was working on a program and figured out how I could increase the storage capacity of an integer inside of a variable. The formula is as following New_Space = Old_Space + Value_of_Integer*Base_Being_Used^Position_of_integer Example: Old_Space = 1,000,000 Value_of_Integer = 12 Base_Being_Used = 100 Position_of_integer = 1 New_Space = 1,000,000 + 12*100^1 New_Space = 1,012,000 ** The Above would have 2 integer values with max length of 99 able to be store in a single integer. Notes: - The number of positional values for the Space (Old/New) is equal to the Base being used. So if the base is 100 and the space is 1,000,000 then the space has 2 positions that can be used. - The integer as a maximum value limit before going outside of its given "cell" equal to the size of the base. - When the maximum size of the integer increases, the number of positions of the integer decreases. Possible use cases: If you were to expand the maximum base size then you will be able to increase the maximum number of potential positions for the integer as well as increasing the maximum size of the integer. Link to comment Share on other sites More sharing options...
Sensei Posted May 5, 2021 Share Posted May 5, 2021 (edited) In the computer science, "integer"/"int" is primitive data type which is stored (typically) in 32 bits, regardless of what value it contains. It can be unsigned or signed. Unsigned 32 bit integer can store values between 0 to 2^32-1 = 4 294 967 295 (~4.3 (US/UK) billions). If not all bits are used, we can pack couple values into one primitive datatype. The simplest example of it is bit field: https://en.wikipedia.org/wiki/Bit_field e.g. if you have value ("value1") in range 0...16 777 215, which fits 100% in 24 bits.. you can merge it with yet another value ("value2") in range 0...255 which fits in 8 bits. data = ( value1 << 8 ) | value2; (which is equivalent to value1 * 256 + value2) To extract value1 from data we need to do: value1 = data >> 8; (which is equivalent to data/256) and to extract value2: value2 = data & 0xFF; (which is equivalent to data%256) In the more complex cases, there are needed left/right binary shift operators together with binary and (&) operators. Binary left-shift is equivalent of multiplication by 2^x. Binary right-shift is equivalent of division by 2^x (without remainder). And binary and (&) operator is equivalent of modulo. They are much faster for CPU than equivalent arithmetic operations. Knowing it, we can pack/unpack values which don't fit perfectly inside of bit/binary boundary. e.g. on the example of time: you have variables seconds and minutes, they are in range 00...59. Hours variable is in range 00...23 packed_time = ( ( hours * 60 ) + minutes * 60 ) + seconds you end up with value in range 0 ... 86399, which is stored in 17 bits (2^17 = 131072) Previously, you would have to have 3 bytes = 24 bits used not optimally for hour, minute and second variables. Remaining bits where always 0, just taking space. Quote Created a system for increasing integer storage No, you did not. Rediscovered just the wheel. Widely known and used even by CPU engineers to save space in the CPU registers.. Edited May 5, 2021 by Sensei Link to comment Share on other sites More sharing options...
ALine Posted May 5, 2021 Author Share Posted May 5, 2021 51 minutes ago, Sensei said: Quote Created a system for increasing integer storage No, you did not. Rediscovered just the wheel. Widely known and used even by CPU engineers to save space in the CPU registers.. Really huh, I thought I discovered something ground breaking there. It just goes to show that by going through and presenting your ideas to others it will allow for an honest critique of your work and updating my previous falsely held beliefs. I honestly thought I had something there for a second, could have saved a lot of time just posting the idea when I had it. Self Reflection: 2 hours ago, ALine said: So the other day I was working on a program and figured out how I could increase the storage capacity of an integer inside of a variable. The above section is very misleading in which it states that I had the idea the other day when in fact I had the idea about a month ago and have been working on it on and off sense. I would not say that I put to much effort into it, however it is enough to justify a little bit of anger at myself for not asking about the idea before hand. I want to apologize for the deception on my part. My whole topic starter kind of also feels very "showey" or giving the impression that it is world changing thing. That was not intentional and was probably my ego slightly showing along with me being impatient when writing it up. I will try and work on that the next time I have an idea and want to share it with others on this forum. The reason that I am sharing this is to self reflect on my current actions so that I can better improve on my later posts along with trying to become better at understanding different things. Also I want to have a sort of something that I can go back to and view for future reflection. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now