145

And THAT is how you stuff a 4x8 bitmap into a single int.

Comments
  • 15
    I don't get it, what's the point of converting it into int?
  • 4
    I don't know that much about binary calculations, but doesnt the transition from 4*8bits to one binary number require conversion to string first?
  • 9
    @DevForTheMoney no necessarily ex in c you could bit swift them in and out in the order you want
  • 5
    are you hinting some kind of compression algorithm here?
  • 2
    I always sketch stuff like this instead of participating on history class etc as well
    :D
  • 1
    @mrsulfat
    That is interesting, thanks!
  • 4
    I never looked at storing array elements in this way. This is quite interesting!
  • 38
    I'm actually a bit shocked that this is seems to be something new for many of you. Shouldn't be some basics about memory representation and interpretation common knowledge amongst developers. I'm aware that not all of you have degrees and some are just starting to learn, but still.
  • 2
    But it's only a black/white image so it's not really feasible
  • 5
    @ThermalCube For bitmap fonts it is enough
  • 3
    Finally found it! https://advanced-ict.info/interacti...
    now you can play it online!
  • 1
    but it's 64 bit
  • 3
    @taosif7 No
    @DevForTheMoney No
    @Milind1997 Ultra efficiency
    @AlexDeLarge Yes!
  • 13
    @AlgoRythm efficiency depends on how you intend to use it. If you access it by pixel the compiler will store each pixel at its own byte and it takes 8 times the space it does now. Yet you can force it to be stored in a single integer but if you access a pixel then the compiler will insert code that extracts the pixel from the byte it is stored in (you can't access less than a byte). So all you can do with this method is trading CPU time by memory consumption, decide wisely.
  • 6
    @JustKidding Yeah, true, but there really isn't any reason today to store characters in a single int anyways (Except for the reason "because I can"), so there isn't really any decision to make - both will perform approximately the same. Just wanted to do some science-y shit while I was bored at work.
  • 3
    actually did something like this with bitmaps that I wanted to store in an AVR chip's flash memory
  • 10
    fun fact, a full 2048 game state fits into a single `long`
  • 1
    @Milind1997 For bitmasking for example, so you can make automatic tile system.
  • 0
    @succcubbus 2048, as in, the mobile puzzle game?
  • 0
  • 0
    Casio used a similar method to pack 5x7 bitmap characters into ten hex digits on the FX-850P. For each column (there are 5), bit 0 is ignored, bit 1 is the bottommost pixel and bit 7 is the topmost one, take a 2-digit hex of that and concat the whole thing, you've got 10 hex digits you can pass to DEFCHR$ to define *your **own** characters*! Wow!
  • 7
    There is something I don't quite get: you are storing 4 bytes of data into a 4 bytes integer, what's amazing about that ? Am I missing a revolutionary break through ?
  • 4
    Isn't this the obvious way to store 32 bits?
    Also, how is this excessive?
  • 2
    @deodexed Absolutely not. It's just cool, old-school graphics, which are incredibly uncommon these days. I could have made it an array of BOOL types or something stupid (but easier) like that, but instead opted for this solution, which requires an understanding of bit operations.
  • 2
    @Root Yes! But using bits for graphics is not so obvious anymore. That's why I said "excessive", although, this was an exaggeration.
  • 0
  • 8
    @JustKidding
    I think it just shows how far IT has gotten in general. There are now people out there that can make a living off programming while they don't even know how computer memory works, let alone know how to manage it!

    Thanks to people studying the field others won't have to, which is basically the fundamental reason were not bashing each others skulls in with rocks anymore.

    Hurrah civilization?
  • 8
    The amount of people suprised by this is too damn high!
  • 4
    @AlgoRythm now what astonishes me the most is the amount of people not nothing the basics
  • 0
    @ThermalCube use 4 layers of this and you can get 16 colors.
  • 7
    @DevForTheMoney seriously I think that is a really bad development. I don't say that we should throw away all the abstraction and still only use assembler. It is indeed good that we don't have to do it.

    BUT saying that we don't need to understand the basics anymore is bullshit. When you write e.g. a web app you should have at least a coarse understanding of what happens in your browser and how that affects your system. The fact that people do things without knowing their implications is the reason for many performance and security issues.

    There is a HUGE difference between throwing away deprecated knowledge and throwing away basic knowledge. What has been posted in this thread is not deprecated but basic and therefor should be known by anyone doing anything serious in this field.
  • 1
    I wonder how many of those who were "shocked that not many people know this" actually understood
  • 0
    And this is why you should learn a language like JavaScript to make a web interface where you paint/select the pixels and you get the uint32 value of that bitmap.
  • 1
    Btw, I'm the only one that thinks 4x8 fonts are ugly? Why not use 5x7 (5x9)?
  • 1
    @LuxARTS Yes, always use odd width and height for fonts (especially for things like the T)
  • 1
    @LuxArts Because neither 5×7 nor 5x9 is 32 so neither of them would fit into a 32-bit integer.
  • 0
    @AlgoRythm why you need to store in 32 bit? I mean, you will not use a significant less amount of memory using 4x8.
  • 0
    @AlgoRythm @LuxARTS I mean significant to the hardware, of course if you use 5x7 you have to use 5 bytes instead of 4 bytes from 4x8 but unless you are planning to add the alphabet in a lot of languages you will not have memory problems (and I'm thinking in a cheapy 8 bit microcontroller).
  • -1
    @JustKidding But hey, how can you put that requirement on people? If developers were hired only if they had the very bare bones underlying knowledge of the language we wouldn't have nearly as many developers as we do. I know plenty of people who are amazing programmers, and who writes wonderful code, but I also know they miss some of the core concepts. Knowing how GC works or how to optimize? Sure. But storing a god damn bitmap in an integer? I can't really see where this would come in handy for a Node.js developer. And I definitely don't think any self taught developer should have to know this.
  • 0
    @JustKidding And hell, have some respect
  • 0
    If you were to send it to someone, maybe use hex or 32bit encoding or even 64bit encoding.

    If you really want some compression use huffman
  • 3
    @ScriptCoded
    This is not even anything difficult. But it makes use of an incredibly fundamental concept, which is frickin BITS AND BYTES. Many developers don't regularily work on that level, but there is still no way any professional developer can get around being familiar with that concept at least. Also the concept that data is basically meaningless before it is interpreted is definitely elementary and since you are always working with nothing but data, that is actually useful to know when optimizing, because you can deligate a lot of information from the stored data to the interpreter of the data (which is basically compression).
  • 1
    @ScriptCoded
    And just the other way around, you can make data easier to be interpreted. And thus faster to use. So not at all trivial.
  • 0
    @simulate I totally agree, knowing how bits and bytes work isn't trivial at all, but being a dick because some people haven't discovered a particular case isn't at all an okay thing to do.
  • 2
    @ScriptCoded First of all I can put any requirement on anyone if I feel the need to do so.

    What upsets me is not the fact that some devs don't know relevant basic concepts but the mindset that they don't need to know about this because they're doing some high level things as JS.

    I don't know all concepts myself either but I don't go out and shout I don't need to know how integers work because my language doesn't have types (simplified example ofc). These things are relevant, even for high level languages. Which brings me to the next point, complexity. Understanding the simple concepts is required to understand the complexity that is imposed by powerful languages. Running as JS app in Chrome seems simple but it inherits the complexity of million of lines of code. And even though you don't see them you should know they're there and you should care about them (as they will have impact on your users and on security).
  • 2
    @ScriptCoded Also I'm not a dick about the fact that people don't know this but about their mindset that some of them think they don't need to know/learn this. If you think you're too good to be required some basic knowledge (hint: you never are) there isn't much respect I can show you.
  • 0
    @ScriptCoded No one is being a dick here, it is just pretty ignorant to assume you dont need to know something, when you dont understand it yet lol. I mean I know that idea myself of course (Ive been in school) but it is a really toxic attitude.

    I was just surprised that this wasnt common knowledge to anyone who calls himself a programmer.

    I think an elefant in the room here, and an issue that is often not really articulated among developers, is that there are actually huge differences and other challanges with low level and high level languages. They are completely different playgrounds.

    It doesnt matter which one you prefer, they have completely different focusses, but they are yet entirely dependent on one another. So it never hurts to know what the other end of the table is talking about.
  • -1
    @JustKidding
    Sure, can't stop you from putting requirements on people...

    Thing here is that you're getting upset because people haven't come up with the idea to store an array in an integer. It's like saying people are stupid for not have realized that cereal goes well with apple juice (haven't tried though). And not only that, but you can't seem to skip harassing people who's actually making a career of programming for not having a degree.
  • 0
    Congratulations. This does not belong on /r/iamverysmart.
  • 1
    @ScriptCoded Thats why I said that I'm aware that some of you are still learning. And I also already said that it actually upsets me that some people think they're so smart that they don't need to know basics.

    Btw. this has nothing to do with having a degree. I've met people without a degree that have a really deep understanding of what's going on under the hood and also people with a degree that I wonder how they got it.

    But I'm repeating myself and it seems that actually reading my comments isn't important so be free to stay in your bubble and feel being harassed ¯\_(ツ)_/¯
  • 0
    But you don't know what's the grid size, is it 1x32? 2x16?
  • 0
    @crisz it says 4x8
  • 0
    So it only support this grid? Nice
  • 1
    Every solution has tradeoffs. That's the beauty and curse of programming. If it's not that common to store fonts in an array of ints it doesn't mean nobody tried, it means the applications of such compression don't have much value. You could write in assembly and be super efficient but we're humans and we like abstractions.
    Sure you can use pifs and have very (very) low space complexity but finding the sequence of bytes that actually represent something meaningful will take forever.

    pifs: https://github.com/philipl/pifs
  • 1
    @muliyul Not compression, just encoding, since all of the data is still there.
Add Comment