News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Please help unpack and PACK the data in WORD / DWORD

Started by BytePtr, December 13, 2009, 12:03:55 AM

Previous topic - Next topic

qWord

FPU in a trice: SmplMath
It's that simple!

dedndave

maybe you can show us how more values are stored
can it be negative ? - show us how some negative values are stored
what is the maximum value ? - show us how that is stored
what is the minimum value ? - show us how that is stored
show us how 0.0, 0.5, 1.0, 1.5 are stored

MichaelW

I did a quick test to see if the stored values might be half-precision floating-point numbers, but in that format 2.0 is 4000h.

http://en.wikipedia.org/wiki/Half_precision


eschew obfuscation

dedndave

it could be as simple as 2 bits ahead of the DP and 14 bits after

xx.xxxxxxxxxxxxxx

the range would be 0 to +3.99993896484375 (which is 3 + (16383/16384))

BytePtr

Solved this problem, by using typecasting to "WORD" and "shr 16"
To get higher and lower values packed in DWORD.

I don't know why, but it worked for me.

I have alot to learn.

raymond

QuoteThe numbers are fixed point always. Not floating.

If the "tool" he is using is the MixLib library for fixed point math ( http://www.ray.masmcode.com/fixmath.html ), he would be getting 20000h for 2.0. BytePtr was probably correct.
When you assume something, you risk being wrong half the time
http://www.ray.masmcode.com

BytePtr

Hi again all.
I have a DWORD32 (unsigned int). The value i will hold in this is maximum: 526271.
Also i would like to store single digit in it, just one of the: 0, 1, 2, 3, 4.

The big number max is 526271 as i said, but it changes (could be even 0), same with single small number, it could be anything from 0 to 4.


Is it possible somehow pack this info together and later also unpack the big number and this single digit, without data loss?
TIA

jj2007

No problem...

include \masm32\MasmBasic\MasmBasic.inc   ; download
   Init
   mov eax, 4   ; Factor A
   shl eax, 28
   mov ebx, 526271   ; Factor B
   or ebx, eax   ; A or B
   nop

   mov eax, ebx   ; read Factors
   sar eax, 28   ; shift out B
   Print Str$("Factor A=%i\n", eax)

   mov eax, ebx   ; read Factors
   and eax, 1111111111111111111111111111b   ; isolate A
   Print Str$("Factor B=%i\n", eax)

   Inkey "ok"
   Exit
end start

Factor A=4
Factor B=526271

BytePtr

I started to read this:
http://webmasters.physics.upatras.gr/mirrors/assembly/Page_AoA/4_5.pdf

And even tried to code out something, but not the way you did it.
I wish i could throw out code like this in a seconds.

Thanks alot jj2007. I will credit you for this.