123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|600|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz Max -> Byte To Nibble in BMAX?

Sun, 07 Feb 2010, 22:03
Mog
Because i'm stupid with bitshifts and converting between datatypes, here's a challenge - How do you convert a byte (8bit) into 2 nibbles (4bit) split down the middle.

-=-=-
I am Busy Mongoose - My Website

Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb

Current Project: Pyroxene
Mon, 08 Feb 2010, 01:06
Cower
I do not follow. A byte is already two 4-bit pieces in a sense, so what could you possibly need to convert it to?
Mon, 08 Feb 2010, 01:25
Phoenix
I suppose you're after something like this (in vanilla Blitz):

Mon, 08 Feb 2010, 02:04
Mog
Cower, Two Nibbles. It's a long story, just need it...

-=-=-
I am Busy Mongoose - My Website

Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb

Current Project: Pyroxene
Mon, 08 Feb 2010, 11:03
Scherererer
Mog: Memory can't be addressed into nibbles, so you either have to move the data from the upper half of the byte to another byte, or do weird shifts depending on which half you need to operate on.

For instance, an addition to the upper-half would require you shift the second operand to the left by 4 and then add. But note, if you try and add a number to the lower-half then it is possible you could overflow into the upper half (e.g. you have your byte : 0000 1111 and add one, then you get 0001 0000, which is obviously wrong since the lower byte now equals zero and the upper byte went from 0 to 1, even though it should technically not be effected at all).

And for multiplication and division, forget about it, it would be better to just move the bits to a temporary register and then shift them back into the byte after being operated on.

You could in theory extract the bits you need, operate, and then put them back, but that would be a larger CPU cost.

If you're just trying to save space then I don't think it's worth it at all on modern machines, unless there is some other reason...?

-=-=-
YouTube Twitter
Computer Science Series: Logic (pt1) (part 2) (part 3) 2's Complement Mathematics: Basic Differential Calculus
Mon, 08 Feb 2010, 11:51
JL235
Instint: Just mod the result. That'll allow you to stay within the bounds of a nibble. Modular Arithmatic is used a lot in cryptography.
Mon, 08 Feb 2010, 12:35
Phoenix
Is this question answered or not?
Mon, 08 Feb 2010, 14:58
Jayenkai
Yep, you pretty much answered it right up top. Whether or not memory DOES / DOES NOT work in that way, it's still just a bunch of 1's and 0's. Find what it can fit into, and use it.
Doesn't matter if the language says "But.. duh! wah?!"
So long as you can get it in, and more importantly, get it out again, you can easily fit the word Banana into 48281634

Just because the language doesn't accept it in the interim doesn't mean the data's wrong.

Split it, Shove it together, and split it again later.
Phoenix's solution was spot on.

-=-=-
''Load, Next List!''
Mon, 08 Feb 2010, 15:14
Mog
Question is answered. It's needed because this weird format we've came across in a project used a byte to store nibble values in multiple ways- annoying :/ I don't need it for space, but someone else did...

-=-=-
I am Busy Mongoose - My Website

Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb

Current Project: Pyroxene
Mon, 08 Feb 2010, 17:34
steve_ancell
If you split the number 255 into two nibbles, what would be the result ?

Would it simply be 15 : 15 (1111 : 1111) ?, or would the result be translated as 240 : 15 (11110000 : 00001111) ? but without the zero's

No actual reason for this question, just curious !
Mon, 08 Feb 2010, 17:59
Jayenkai
Properly it should be 15:15, because those were the original two single values.

-=-=-
''Load, Next List!''
Mon, 08 Feb 2010, 19:24
Mog
Just in case anyone was wondering, this came up as we're trying to figure out a graphics format that uses RLE to store transparent pixels. Quoting the person i'm working with and their notes:

Once you have read all the scan lines you can decode the run length encoding by reading the first byte of the scan line. It will be in the format XXXXYYYY where each letter is a bit. The first four bits XXXX will contain the number of contiguous transparent pixels. So you just repeat the transparent index (which is zero) that many times. The next four bits YYYY indicate the number of non-zero bytes following.



This is why i needed nibbles.

-=-=-
I am Busy Mongoose - My Website

Dev PC: AMD 8150-FX, 16gb Ram, GeForce GTX 680 2gb

Current Project: Pyroxene