Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert a Binary Character to Integer
Message
From
09/08/2003 04:02:46
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
08/08/2003 15:28:55
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00818393
Message ID:
00818550
Views:
21
>Hi,
>I am working with different Latin American countries and they send me every month different .dbf files with data. Some of these countries use BRO Plus as .dbf editor. I have one field called quantity and it's binary! I tried with the CtoBin() function in fox, but it didn't work. If I use the BRO's command BIN2L works! If I do the following example in fox works also:
>aa=25
>bb=BinToC(aa)
>?CtoBin(bb) &&Returns 25.
>
>In this example the convertions works perfectly!
>
>I think that I have the problem with the bits. I think they convert data with 16bits and fox 8.0 uses 32bits.
>Anyway, does anybody know how can I convert this binary field into an integer. (consider that this binary data was generated with a program called BRO and the command used was L2BIN()
>
>Thanks!

Assuming length of field matches the size of integer (1,2,4 - 8,16,32 bits) :
function Str2Int
lparameters tcStr
local lnValue
lnValue = 0
for ix = 1 to len(tcStr)
 lnValue = lnValue + asc(substr(tcStr,ix)) * 256^(ix-1)
endfor
return lnValue
PS: RtlMoveMem should be faster. If data is huge use RtlMoveMem :
DECLARE RtlMoveMemory IN WIN32API ;
	INTEGER @DestNumeric, ;
	STRING @pVoidSource, ;
	INTEGER nLength

function Str2Int
lparameters tcStr
local lnValue
lnValue=0
RtlMoveMemory(@lnValue, tcStr, len(tcStr))
return lnValue
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform