-5

I am looking forward to the way convert some data into real numbers

Here are an example of the data

0400 0000 cf40 2761 d2ff 5552 ceff 5652
e0ff 5b52 e0ff 5b52 eaff 5f52 f4ff 5b52
eaff 5852 eeff 5752 f2ff 5952 eeff 5a52
d8ff 5452 d4ff 5652 caff 5452 ccff 5352
d2ff 5552 c2ff 5a52 ccff 5e52 e2ff 5652
eaff 5852 f0ff 5652 e8ff 5452 e8ff 5452
eaff 5552 deff 5a52 f0ff 5f52 faff 5b52
0a00 6152 0400 6352 f8ff 5f52 0000 5c52
f8ff 5952 0200 5452 0000 5452 f2ff 5952
f8ff 5a52 0400 5652 0400 5652 f2ff 5c52

After some survey, I found that it seems that hex data file(or raw binary format) I tried many methods like hex editors and other functions of R and python, but it does not work for me

If you have any ideas for these data, please let me know! Thank you a lot!

ainsuotain
  • 186
  • 2
  • 13
  • Related: https://stackoverflow.com/questions/19502092/convert-hex-to-decimal-in-r/52127598 – Mikko Oct 18 '21 at 06:38

3 Answers3

2

You can use the simple python functions. I have stored the Hexa in a variable. then you can use the split function to convert hex in the list as below. To transfer the list of Hexa in numbers use a print function with for loop.

1. For i.e. hex_string = "your hexa data" 
2. For i.e. ist = (hex_string.split(" "))

Check the below for the entire code.

hex_string = "0400 0000 cf40 2761 d2ff 5552 ceff 5652 e0ff 5b52 e0ff 5b52 
eaff 5f52 f4ff 5b52 eaff 5852 eeff 5752 f2ff 5952 eeff 5a52 d8ff 5452 
d4ff 5652 caff 5452 ccff 5352 d2ff 5552 c2ff 5a52 ccff 5e52 e2ff 5652 
eaff 5852 f0ff 5652 e8ff 5452 e8ff 5452 eaff 5552 deff 5a52 f0ff 5f52 
faff 5b52 0a00 6152 0400 6352 f8ff 5f52 0000 5c52 f8ff 5952 0200 5452 
0000 5452 f2ff 5952 f8ff 5a52 0400 5652 0400 5652 f2ff 5c52"

list = (hex_string.split(" "))
for i in list:
     print(int(i,16))
Vishal
  • 128
  • 13
1

In R, broman::hex2dec function converts hex to decimal.

install.packages("broman")

library(broman)

dummy <- read.table(text = "0400 0000 cf40 2761 d2ff 5552 ceff 5652
e0ff 5b52 e0ff 5b52 eaff 5f52 f4ff 5b52
eaff 5852 eeff 5752 f2ff 5952 eeff 5a52
d8ff 5452 d4ff 5652 caff 5452 ccff 5352
d2ff 5552 c2ff 5a52 ccff 5e52 e2ff 5652
eaff 5852 f0ff 5652 e8ff 5452 e8ff 5452
eaff 5552 deff 5a52 f0ff 5f52 faff 5b52
0a00 6152 0400 6352 f8ff 5f52 0000 5c52
f8ff 5952 0200 5452 0000 5452 f2ff 5952
f8ff 5a52 0400 5652 0400 5652 f2ff 5c52", header = F)

apply(dummy, 2, hex2dec)

         V1    V2    V3    V4    V5    V6    V7    V8
 [1,]  1024     0 53056 10081 54015 21842 52991 22098
 [2,] 57599 23378 57599 23378 60159 24402 62719 23378
 [3,] 60159 22610 61183 22354 62207 22866 61183 23122
 [4,] 55551 21586 54527 22098 51967 21586 52479 21330
 [5,] 54015 21842 49919 23122 52479 24146 58111 22098
 [6,] 60159 22610 61695 22098 59647 21586 59647 21586
 [7,] 60159 21842 57087 23122 61695 24402 64255 23378
 [8,]  2560 24914  1024 25426 63743 24402     0 23634
 [9,] 63743 22866   512 21586     0 21586 62207 22866
[10,] 63743 23122  1024 22098  1024 22098 62207 23634
Park
  • 14,771
  • 6
  • 10
  • 29
1

In python

data = [['0400', '0000', 'cf40', '2761', 'd2ff', '5552', 'ceff', '5652'],
        ['e0ff', '5b52', 'e0ff', '5b52', 'eaff', '5f52', 'f4ff', '5b52'],
        ['eaff', '5852', 'eeff', '5752', 'f2ff', '5952', 'eeff', '5a52'],
        ['d8ff', '5452', 'd4ff', '5652', 'caff', '5452', 'ccff', '5352'],
        ['d2ff', '5552', 'c2ff', '5a52', 'ccff', '5e52', 'e2ff', '5652'],
        ['eaff', '5852', 'f0ff', '5652', 'e8ff', '5452', 'e8ff', '5452'],
        ['eaff', '5552', 'deff', '5a52', 'f0ff', '5f52', 'faff', '5b52'],
        ['0a00', '6152', '0400', '6352', 'f8ff', '5f52', '0000', '5c52'],
        ['f8ff', '5952', '0200', '5452', '0000', '5452', 'f2ff', '5952'],
        ['f8ff', '5a52', '0400', '5652', '0400', '5652', 'f2ff', '5c52']]
for row in data:
    for value in row:
        value = int(value, 16)
print(data)

basically I didn't know if you wanted it to be presented like that or not so I made a 'matrix' (its a list of lists if you want the actual terminology, but its basically just a matrix) of your values. Then converted them to decimal using the int() function.

EDIT: Decided to make it look a littttle prettier

data = [['0400', '0000', 'cf40', '2761', 'd2ff', '5552', 'ceff', '5652'],
        ['e0ff', '5b52', 'e0ff', '5b52', 'eaff', '5f52', 'f4ff', '5b52'],
        ['eaff', '5852', 'eeff', '5752', 'f2ff', '5952', 'eeff', '5a52'],
        ['d8ff', '5452', 'd4ff', '5652', 'caff', '5452', 'ccff', '5352'],
        ['d2ff', '5552', 'c2ff', '5a52', 'ccff', '5e52', 'e2ff', '5652'],
        ['eaff', '5852', 'f0ff', '5652', 'e8ff', '5452', 'e8ff', '5452'],
        ['eaff', '5552', 'deff', '5a52', 'f0ff', '5f52', 'faff', '5b52'],
        ['0a00', '6152', '0400', '6352', 'f8ff', '5f52', '0000', '5c52'],
        ['f8ff', '5952', '0200', '5452', '0000', '5452', 'f2ff', '5952'],
        ['f8ff', '5a52', '0400', '5652', '0400', '5652', 'f2ff', '5c52']]
for row in data:
    string = ''
    for value in row:
        value = int(value, 16)
        string = string + str(value) + ' '*(10-len(str(value)))
    print(string)

Output:

1024      0         53056     10081     54015     21842     52991     22098
57599     23378     57599     23378     60159     24402     62719     23378
60159     22610     61183     22354     62207     22866     61183     23122
55551     21586     54527     22098     51967     21586     52479     21330
54015     21842     49919     23122     52479     24146     58111     22098
60159     22610     61695     22098     59647     21586     59647     21586
60159     21842     57087     23122     61695     24402     64255     23378
2560      24914     1024      25426     63743     24402     0         23634
63743     22866     512       21586     0         21586     62207     22866
63743     23122     1024      22098     1024      22098     62207     23634
James E
  • 186
  • 9