08-08-2012 05:55 PM
Hi,
In my application I am creating a host buffer (dwords data type) which I receive form the data acquisition hardware. 2 of these data words makes 64bits. I would like to create 36bits out of these 2 DWORDS and write to a file stream.(first dword + 4bits of LSBs of 2nd dword). the memory format i am trying to create is 36bits X 512. Can somebody offer me any pointers on this?
Thanks,
Suni
08-09-2012 05:51 PM
Hi,
Can sombody help me on this issue?
i need to create ont 36bit word from two 32bit words.
Thanks for all your help.
Suni
08-09-2012 08:59 PM
There's no "clean" solution to this that I can see.
C as implemented on PC's doesn't support a 36 bit integer type, and files are streams of 8 bit bytes, so you're kindof stuck.
You could write out 5 bytes of binary data for each of your data points, "wasting" 4 bits for each data point, but creating and then reading these would be something of a mess. You have to consider "endian-ness" (what order do you write the bytes for each value out to the file) and you're doing your own formatting. But, you could put the 36 bit values into 64 bit ints, then mask off 5 bytes one at a time and write each byte separately out to the file. You'd have to match this formatting scheme of course whenever you tried to read the file.
If you're writing to mass storage of some kind you might consider just writing out (and reading in) a full 64 bit int - C will take care of the formatting - unless you're talking GB's of data I'd say this is the easient thing to do.
08-10-2012 12:08 AM
As memchar already said : It makes no sense CVI to hold 36 bit values in PC memory without wasting some bits. Using 64 bit variables and masking off unneeded bits is much better.
But writing to a file without wasting bits should be possible because 8*36 = 288 = 9*32 and you have a multiple of 8 (512) values to write. With some mask , shift and or operations you can put 32 bit of the first 36 bit value in the first 32 bit to write, then put the remaining 4 bits of the first and 28 bits of the second 36 bit value into the second 32bit , then the remaining 8 bits of the second 36 bits and 24 bits of the third 36 bits into the third 32bit and so on ...
08-10-2012 09:27 AM
Thanks for all your responses.
Mkossmann mentioned that with some maks, shift annd or operations I can do this. can you please inform me with the C functions involve in this? Thanks
08-10-2012 05:16 PM
Thanks again. I think i created the format i wanted. only problem i ran into was memory block was 36bitsX 510= 18360bits= 32bitsX 573.75. i coudn't fit exact number of bits to 32bit format.
08-10-2012 05:24 PM
i am sorry i said the format has 36bit words of 512 address. inital buffer has 64bit X 510 locations. after adding the header which has 2 of 36bit words it becomes 512 format.