Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
8bit or 16bit or 32bit words?
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00884810
Message ID:
00885197
Views:
14
>>>>I'm looking at some code and they are saving values in either 8bit or 16bit or 32bit words. How can I do that in FoxPro. Sorry if this is detailed enough but I don't understand what these "words" are. It looks like they take an ASCII value and transform it into an different word.
>>
>>I was looking at the LZW compression method. There are example on the web in C and in VB. I have the method down on how to create the "compression table" but when writing the data out it creates new fake ascii values. So 0 to 255 are the normal one but when they create a new value in the compression table they assign it value 256 for the first one so that we know it's in the "compression table lookup" and not just a normal ascii value. So to write out the 256 they say you write it in 8bit/16bit/32bit values. The C code I started looking at is http://www.dogma.net/markn/articles/lzw/lzw.htm. The code is at the bottom of the webpage
>
>That's just a VFP short since 255 is the maximum value of a byte. VFP handles this in the proper manner. Just as an FYI, the storage is in least-to-most significant byte. So while we would write this in hex as 0x0100, it's internally stored in the reverse. In binary, it would look like this:
>
        LSB            MSB
>     0000 0000      0000 0001
I went home and converted a VB program to FoxPro that is suppose to convert to 8bit characters. The outputs of the two programs are identical. Here is the FoxPro program but I still don’t understand how that’s 8bit or how to make it more than 8bit. For some reason the first value in the array must be 256 and the last two 257 and 0
PRIVATE la_Values
DIMENSION la_Values[4]
la_Values[1] = 256
la_Values[2] = ASC('T')
la_Values[3] = 257
la_Values[4] = 0
? Eight_Bit(@la_values)

FUNCTION Eight_Bit(pa_values) 
  LOCAL lc_bits,   ;
        lc_return, ;
        ln_cntr,  ;
        ln_alen
  STORE SPACE(0) TO lc_bits, ;
                    lc_return
  ln_alen = ALEN(pa_Values) - 1
  FOR ln_cntr = 1 TO ln_alen + 1 
     lc_bits = PADL(Num2Bin(pa_values(ln_cntr)), 9, '0') + lc_bits
  ENDFOR

  FOR ln_cntr = (LEN(lc_bits) - 7) TO 1 STEP -8 
     lc_return = lc_return + CHR(Bin2Num(SUBSTR(lc_bits, ln_cntr, 8)))
  ENDFOR 
  *-- Drop the first one it's always chr(0)
  lc_return = SUBSTR(lc_return, 2)
RETURN (lc_return)

FUNCTION Num2Bin(pn_num) 
  LOCAL ln_num, ;
        lc_bin
  lc_bin = SPACE(0)
  ln_num = pn_num
  DO WHILE ln_num <> 0 
      lc_bin = TRANSFORM(MOD(ln_num, 2)) + lc_bin
      ln_num = INT(ln_num / 2) 
  ENDDO 
RETURN (lc_bin) 

FUNCTION Bin2Num(pc_bin) 
  LOCAL ln_cntr, ;
        ln_num
  ln_num = 0 
  FOR ln_cntr = 1 TO LEN(pc_bin)
    IF SUBSTR(pc_bin, ln_cntr, 1) = "1" 
       ln_num = ln_num + 2 ^ (LEN(pc_bin) - ln_cntr) 
    ENDIF
  ENDFOR 
RETURN (ln_num)
Charles

"The code knows no master." - Chuck Mautz
"Everybody is ignorant, only on different subjects." - Will Rogers
Previous
Reply
Map
View

Click here to load this message in the networking platform