Bite operations with ShL and ShR - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26) +---- Forum: Petr (https://qb64phoenix.com/forum/forumdisplay.php?fid=52) +---- Thread: Bite operations with ShL and ShR (/showthread.php?tid=3215) |
Bite operations with ShL and ShR - Petr - 11-16-2024 This demo doesn't focus on reading Byte directly, but shows how to do the same job more easily using _ShL and ShR bit shifting. It took me a while to figure out how to use it, but I thought we could share our experiences with reading bit values from Byte here. Code: (Select All)
RE: Bite operations with ShL and ShR - ahenry3068 - 11-16-2024 Its good code. And I've been playing with similar techniques to pack RAM more tightly on the X16 a neo-retro 8 bit computer. However, I can't see why would ever need this technique on even a barely modern system. It's seems kind of a waste for a relatively small RAM savings. No offense meant. It is quite nice code actually. IMO I just don't see the point. . RE: Bite operations with ShL and ShR - Petr - 11-16-2024 (11-16-2024, 09:34 PM)ahenry3068 Wrote: Its good code. And I've been playing with similar techniques to pack RAM more tightly on the X16 a neo-retro 8 bit computer. However, I can't see why would ever need this technique on even a barely modern system. It's seems kind of a waste for a relatively small RAM savings. What's the point? Huge. Just read the documentation for MP3 or MP4 format, for GIF format, also for TTF font files, for 1-bit bitmaps and so on. Bit fields need to be decoded everywhere, it's a perfectly common practice. RE: Bite operations with ShL and ShR - SMcNeill - 11-16-2024 (11-16-2024, 09:34 PM)ahenry3068 Wrote: Its good code. And I've been playing with similar techniques to pack RAM more tightly on the X16 a neo-retro 8 bit computer. However, I can't see why would ever need this technique on even a barely modern system. It's seems kind of a waste for a relatively small RAM savings. The point is to use a variable for bit-packing. In this case though, I personally think I'd just use a custom type and save myself a lot of shifting and headache. TYPE msl_type game as _byte mask as _byte hour as _byte minute as _byte second as _byte END TYPE 5 bytes with each to use, access, and something everyone can understand at a glance. Compared to 4 bytes which is rather complex for a lot of folks to ever sort out and work with. Trust me, I can promise you which one is easiest to come back to and work on after a 2 year break or whatnot. (11-16-2024, 10:28 PM)Petr Wrote:(11-16-2024, 09:34 PM)ahenry3068 Wrote: Its good code. And I've been playing with similar techniques to pack RAM more tightly on the X16 a neo-retro 8 bit computer. However, I can't see why would ever need this technique on even a barely modern system. It's seems kind of a waste for a relatively small RAM savings. It's also not just for modern formats. Even old-school graphics did this with bit packing for black/white screens. Screen 7(I think) packs it's memory into 4-bit nibbles (half-bytes). It's not rare at all to see this type of thing in use with more advanced code and projects. RE: Bite operations with ShL and ShR - ahenry3068 - 11-16-2024 (11-16-2024, 10:30 PM)SMcNeill Wrote:Ahh. Ok I stand corrected. I just didn't get the context for the code. I didn't think of decoding packed file formats at all. I've been using bit packed variables to save memory and that's what I thought of first... I'll think twice next time.(11-16-2024, 09:34 PM)ahenry3068 Wrote: Its good code. And I've been playing with similar techniques to pack RAM more tightly on the X16 a neo-retro 8 bit computer. However, I can't see why would ever need this technique on even a barely modern system. It's seems kind of a waste for a relatively small RAM savings. RE: Bite operations with ShL and ShR - Pete - 11-17-2024 No worries. A lot of folks think my routines are worthless until I come back to explain them and prove them to be worthless. Pete - I don't give two shifts about a bit. RE: Bite operations with ShL and ShR - PhilOfPerth - 11-17-2024 (11-17-2024, 01:31 AM)Pete Wrote: No worries. A lot of folks think my routines are worthless until I come back to explain them and prove them to be worthless. I bet my routines are worthlesser than your routines! RE: Bite operations with ShL and ShR - Pete - 11-19-2024 Ya mean MORE worthlesser, varmint! Howdy ya xpect folks who visit here ta larn Inglish? - Sam |