Jump to content

Convert 16 bit number to decimal?


Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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")
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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