convert hex to decimal value using python?

Dev

I want to convert hex to decimal value for the bellow given .txt file . specifically in line number 1, only for 73cb for that purposes I have developed python program . BUT it does not work and my output should be: 29643

(10 (0 1 73cb 0))
(13 (0 1 e7ba 0))
(12 (0 1 0 0))
(10 (2 1 73cb 1 3)(
-0.05492209987825172 0.2133354572857093 0.2934898883481872
-0.05491927490082463 0.211290383138306 0.2817208459424883
-0.04367581308239386 0.212758053576771 0.287530716703097
))

with open("test.txt","r") as fi:
    id = []
    for ln in fi:
        if ln.startswith("(10"):
            id.append(ln[9:13])
            sd=print(id)
            dec=int(sd,16)
            print(dec)
veedata

You have assigned the value of variable sd to print() which will return None.

What you need to do is to convert the ln[9:13] to int and then convert it from hexadecimal to decimal.

A code modified from yours is

with open("test.txt","r") as fi:
    id = []
    for ln_count, ln in enumerate(fi):
        if ln.startswith("(10") and ln_count == 0:
            sd=ln[9:13]
            id.append(sd)
            dec=int(sd,16)
            print(dec)

Additionally, I would recommend changing the variable name id to something else since id is the name of an inbuilt function in python. Using id as a variable name will cause function overriding.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

convert hex decimal numbers to decimal using python

Python convert decimal to hex

Convert hex to decimal/string in python

How to convert hex string into decimal value

Convert a hex string into an unsigned decimal value

How to convert Decimal To Hex using VB?

Convert decimal to hex with leading zeros using oracle

How to convert a string to array and convert each of the hex value in array to decimal in python?

How do I convert hex to decimal in Python?

How do I convert hex to decimal in Python?

Python Pandas Subset Hex String, Convert to Decimal

Python How to convert a float as hex to decimal

How to convert decimal to hex and send hex using expect(TCL) script

How to convert 4 Digit HEX (2 byte) to Decimal (Floating) Value Using VB.Net

Python : Convert hex value : from big-endian to little endian and then to decimal

Dart: convert decimal to hex

Long HEX Value Split to 2bytes Hex values or 4bytes Hex Values and convert it to decimal (float) values Using VB.Net

C# Convert hex string to decimal . Why negative value?

How to grab hex value in between a bunch of zeros and convert it to decimal?

Can I convert hex to decimal using the calculator app?

convert first column from hex to decimal using awk

How to convert hex to decimal rgb565 using java?

Transfer hex value to a decimal value

Command to convert Hex to decimal in Linux?

Convert decimal integer to hex in Elixir

Convert decimal NSString to a hex string

Spark: Convert hex string to Decimal

php convert hex to decimal not working

convert HEX string to Decimal in arduino

TOP Ranking

HotTag

Archive