Jump to content

Recommended Posts

Posted (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 by shadowfiend
Posted (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 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
Posted

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")
Posted

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.

Posted

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.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...