on 4/11/07 10:15 PM, E. Tejkowski at [EMAIL PROTECTED] wrote:

> Forgive this repost, but I'm not seeing my original post appearingŠ
> 
> 
> On Apr 11, 2007, at 4:14 PM, Charles Yeomans wrote:
> 
>> On Apr 11, 2007, at 4:48 PM, Daniel Stenning wrote:
>> 
>> 
>>> Anyone know how (in the shortest amount of code ) to get the
>>> integer value
>>> of an OSType - say 'abcd'  ?
>>> 
>> 
>> Here's a function that does not use a MemoryBlock.
>> 
>> Function OSTypeToUInt32(x as OSType) As UInt32
>>    dim char() as String = SplitB(x, "")
>>    return ((AscB(char(0))*256 + AscB(char(1)))*256 + AscB(char(2)))
>> *256 + AscB(char(3))
>> End Function
>> 
>> You could eliminate the split to array, replacing char(i) by MidB(x,
>> i + 1).
>> 
>> Function OSTypeToUInt32(x as OSType) As UInt32
>>    return ((AscB(MidB(x, 1))*256 + AscB(MidB(x, 2)))*256 + AscB(MidB
>> (x, 3)))*256 + AscB(MidB(x, 4))
>> End Function
>> 
> 
> 
> Unless I'm overlooking something, I think Charles' examples are
> missing POW. Here's the (somewhat verbose/old-school) function I use:
> 
>    Dim i, theLong, aChar As Integer
>    for i=4 downTo 1
>      aChar=Asc(Mid(theOSType, i, 1))
>      theLong=theLong+(aChar*(Pow(256, 4 - i )))
>    next
>    return theLong
> 
> And come to think of it, I think that all of these examples will fail
> if used on Windows. In that case, you'd need to make the i-loop go in
> the opposite direction (1 to 4).

Charles' function is correct. Look carefully at where the multiplies and the
brackets are. It helps to simplify it. Take the second example. If you
replace AscB(MidB(x, ?)) with X1 through X4 and inject a little white space
you can see what is happening.

    return ((X1 * 256 + X2) * 256 + X3) * 256 + X4

Chris


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to