shadowfiend Posted March 19, 2008 Share Posted March 19, 2008 (edited) Howdy folks. Ok I can use 'Dec' function to convert my 8 bit numbers but does'nt seem to work for 16 bit. E.g. $hex = 4600; 4600 = 70 when converted to decimal $decoder_string = Dec($hex);convert to decimal MsgBox(0,"$decoder_string = ", $decoder_string) The result should come out as 70 but it comes out as 17920. The number is in little endian format. Is there a function to handle this? Thanks. Shadowfiend. Edited March 19, 2008 by shadowfiend Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 19, 2008 Share Posted March 19, 2008 (edited) Howdy folks. Ok I can use 'Dec' function to convert my 8 bit numbers but does'nt seem to work for 16 bit. E.g. $hex = 4600; 4600 = 70 when converted to decimal $decoder_string = Dec($hex);convert to decimal MsgBox(0,"$decoder_string = ", $decoder_string) The result should come out as 70 but it comes out as 17920. The number is in little endian format. Is there a function to handle this? Thanks. Shadowfiend. You will have to convert to big-endian before passing it to Dec(), obviously. Should have been: $hex = "0046" Also, since you set the value by variable assignment "$hex = 4600" without quotes around the number, it was saved as an INT32 variable to begin with, then String() convert was done automatically when you passed it into Dec(). You are mixing up string encoding with hardware bit encoding. P.S. As for a function to handle it, where did the data come from? In your example you statically assigned a variable. If this is a binary file you are reading, then select the correct mode for FileOpen() to match endianess. Edited March 19, 2008 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
eltorro Posted March 19, 2008 Share Posted March 19, 2008 Howdy folks. Ok I can use 'Dec' function to convert my 8 bit numbers but does'nt seem to work for 16 bit. E.g. $hex = 4600; 4600 = 70 when converted to decimal $decoder_string = Dec($hex);convert to decimal MsgBox(0,"$decoder_string = ", $decoder_string) The result should come out as 70 but it comes out as 17920. The number is in little endian format. Is there a function to handle this? Thanks. Shadowfiend. BitRotate(Dec($hex),8,"W") Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
PsaltyDS Posted March 19, 2008 Share Posted March 19, 2008 BitRotate(Dec($hex),8,"W") Very smooth... Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
shadowfiend Posted March 19, 2008 Author Share Posted March 19, 2008 PsaltyDS, thanks I will bear these points in mind.eltorro, thankyou this seems to be the ticket.I will give this a try and let you know how I get on.Cheers,Shadowfiend. Link to comment Share on other sites More sharing options...
shadowfiend Posted March 19, 2008 Author Share Posted March 19, 2008 Hey that worked like a charm! $hex = "4600";4600 = 70 as a binary word $hex2 = BitRotate(Dec($hex),8,"W") MsgBox(0,"$hex2 = ", $hex2) This indeed produces the answer of 70. Thanks very much guys Shadowfiend. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now