I need to convert doubles from (normal) IEEE format to VAX D-float format.
Does any have (or know of any existing) rutine, that wil do this job ?
regards from Søren R. Christensen
Printable View
I need to convert doubles from (normal) IEEE format to VAX D-float format.
Does any have (or know of any existing) rutine, that wil do this job ?
regards from Søren R. Christensen
I needed the reverse operation once. I found documentation about the VAX D-float format at http://www.openvms.compaq.com:8000/7...bas_um_028.htm . See paragraph 18.2.2 for the info. You'll need to do a lot of bitshifting for this operation, since the exponent is stored in only 8 bits, instead of 11. Also the sign is stored in bit 15, not in bit 0.
Here's the code in C (VAX D-float to IEEE doubles), probably not the most efficient code, but I'm still just a novice in C. The comments are in dutch, but they still might be helpful.
Code:GEOFUNCDLLEXIM double _stdcall DVax2IEEE(double dValue)
{
unsigned char chValue[7], chNew[7];
int iExp, i;
double dNew;
for(i = 0; i < 8; i++) chNew[i] = 0;
memcpy(chValue, &dValue, 8);
//for(i = 0; i < 8; i++) printf("%02X ", chValue[i]);
//printf("\n\n");
//'Sign = 1e bit van byte 1 naar 1e bit van byte 7, geen deling / vermenigvuldiging noodzakelijk
chNew[7] = (chValue[1] & 0x80);
//printf("Sign: %d\n", chNew[7] / 0x80);
//'Exponent = 2e t/m 8e bit van byte 1 en 1e bit van byte 0
//printf("Value * 2: %d\n", (chValue[1] & 0x7F) << 1);
//printf("Value: %d\n", (chValue[0] & 0x80) >> 7);
iExp = ((chValue[1] & 0x7F) << 1) + ((chValue[0] & 0x80) >> 7);
iExp += (1023 - 128);
//printf("Exponent: %d\n", iExp);
//'Eerste 7 bits van exponent naar laatste 7 bits van byte 7
chNew[7] += (iExp & 0x7F0) >> 4;
//'Laatste 4 bits van exponent naar 1e 4 bits van byte 6
chNew[6] = (iExp & 0xF) << 4;
//'Fractie (mantisse)
//'Stap A: Bits 2 t/m 5 van byte 0 naar bits 5 t/m 8 van byte 6
chNew[6] += (chValue[0] & 0x78) >> 3;
//'Stap B: Bits 6 t/m 8 van byte 0 naar bits 1 t/m 3 van byte 5
chNew[5] = (chValue[0] & 0x7) << 5;
//'Stap C: Bits 1 t/m 5 van byte 3 naar bits 4 t/m 8 van byte 5
chNew[5] += (chValue[3] & 0xF8) >> 3;
//'Stap D: Bits 6 t/m 8 van byte 3 naar bits 1 t/m 3 van byte 4
chNew[4] = (chValue[3] & 0x7) << 5;
//'Stap E: Bits 1 t/m 5 van byte 2 naar bits 4 t/m 8 van byte 4
chNew[4] += (chValue[2] & 0xF8) >> 3;
//'Stap F: Bits 6 t/m 8 van byte 2 naar bits 1 t/m 3 van byte 3
chNew[3] = (chValue[2] & 0x7) << 5;
//'Stap G: Bits 1 t/m 5 van byte 5 naar bits 4 t/m 8 van byte 3
chNew[3] += + (chValue[5] & 0xF8) >> 3;
//'Stap H: Bits 6 t/m 8 van byte 5 naar bits 1 t/m 3 van byte 2
chNew[2] = (chValue[5] & 0x7) << 5;
//'Stap I: Bits 1 t/m 5 van byte 4 naar bits 4 t/m 8 van byte 2
chNew[2] += + (chValue[4] & 0xF8) >> 3;
//'Stap J: Bits 6 t/m 8 van byte 4 naar bits 1 t/m 3 van byte 1
chNew[1] = (chValue[4] & 0x7) << 5;
//'Stap K: Bits 1 t/m 5 van byte 7 naar bits 4 t/m 8 van byte 1
chNew[1] += + (chValue[7] & 0xF8) >> 3;
//'Stap L: Bits 6 t/m 8 van byte 7 naar bits 1 t/m 3 van byte 0
chNew[0] = (chValue[7] & 0x7) << 5;
//'Stap M: Bits 1 t/m 5 van byte 6 naar bits 4 t/m 8 van byte 0
chNew[0] += + (chValue[6] & 0xF8) >> 3;
//'Bits 6 t/m 8 van byte 6 vervallen, omdat de bias van de exponent is verhoogd van 128 naar 1023
//for(i = 0; i < 8; i++) printf("%02X ", chNew[i]);
//printf("\n\n");
memcpy(&dNew, chNew, 8);
return dNew;
}
Hi riis!
Thank you. I have now coded a VB routine to convert from
IEEE G-float to VAX D-float.
Your code for doing the opposite conversion has been a great help.
src