Big/Little Endian and Externals - Was how to Display/Print a Hex Number???

Mark Smith mark at maseurope.net
Tue Feb 13 11:03:59 EST 2007


Dave, is this value a product of the binaryDecode function? If so,  
it's usually just a question of chosing the right parameter for the  
platform/processor.

Rather than <if "Intel" is in the processor> or somesuch, (might it  
me "AMD"...), I use this function to determine the endianness of the  
system an app is running on:

function bigEndian
   put binaryEncode("I",1) into tBinNum -- this creates a 4 byte uint  
in host byte order
   repeat for each char i in tBinNum
     put charToNum(i) & space after tList
   end repeat
   return char 1 of tList = 0
end bigEndian

if it returns true then we're big-endian, otherwise little-endian.

Without testing, I think you could use the binaryEncode("h*"....  
(lower case "h") for little-endian processors.

so:

put empty into tHexStatus
if bigEndian() then
   get binaryDecode("H*", myStatus, tHexStatus)
else
   get binaryDecode("h*, myStatus, tHexStatus)
end if

Best,

Mark

On 13 Feb 2007, at 12:36, Dave wrote:

> Hi,
>
> That works great, thanks a lot. One other thing though:
>
> I have an external that will eventually have to work on Mac/Intel,  
> Mac/PowerPC and Windows. The value that is being returned is  
> 0x00000001, however on an Intel Mac it's being displayed as  
> 0x01000000. e.g. it's a Big/Little Endian issue. Is there a  
> standard way to handle this for both platforms???
>
> Thanks a lot for your help.
> All the Best
> Dave
>
> On 13 Feb 2007, at 11:23, Mark Smith wrote:
>
>> If it's a revolution number, you can use <put baseConvert(myStatus, 
>> 10,16)>, if it's a 4 byte binary value, you can
>>
>> put empty into tHexStatus
>> get binaryDecode("H*", myStatus, tHexStatus)
>>
>> and tHexStatus should now contain the value as as hex chars.
>>
>> Hope this helps,
>>
>> Best,
>>
>> Mark
>> On 13 Feb 2007, at 10:52, Dave wrote:
>>
>>> Hi,
>>>
>>> I have a parameter that is passed back to RunRev in a Variable  
>>> from an External Command, e.g. the TranScript line is:
>>>
>>> put myExternalFunction("myHandle") into myStatus
>>>
>>> and the C/C++ line in the External is:
>>>
>>> SetVariableEx(theArgumentArrayPtr[0],"",&myHandle,&myStatus);
>>>
>>> I would now like to display the "handle" as a Hex Value in RunRev  
>>> but for the life of me I can't think how to do it! Guess my brain  
>>> has gone to sleep today! Any help would be appreciated!
>>>
>>> Thanks a lot and All the Best
>>> Dave
>>>
>>> _______________________________________________
>>> use-revolution mailing list
>>> use-revolution at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your  
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-revolution
>>
>> _______________________________________________
>> use-revolution mailing list
>> use-revolution at lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your  
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-revolution
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your  
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution




More information about the Use-livecode mailing list