Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3483334
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:39:44+00:00 2026-05-18T10:39:44+00:00

I am trying to read a txt file which has hexadecimal data. I Want

  • 0

I am trying to read a txt file which has hexadecimal data. I Want to convert them in decimal except one column which I want to convert into binary bits and write them in 8 separate columns.
Sample data set

1/4/2010 15:31 <00000> 0x0001 0x0010 0x0014 0x0000 0x0142 0x0001 0x0001 0x0000 0x028F 0x2007 0x0105 0x00AA 0x005A 0xFA8C 0xFACD 0xFAED 0x003B 0xFFA3 0xFFDE 0x0080 0xFEE0 0xFF2E 0x0000 0x0108
1/4/2010 15:31 <00000> 0x0001 0x0010 0x0014 0x0000 0x0143 0x0001 0x0001 0x0000 0x028F 0x2008 0x0105 0x00AA 0x005B 0xFA8C 0xFACC 0xFAEE 0x003C 0xFFA3 0xFFDE 0x0080 0xFEE0 0xFF2E 0x0000 0x0108
1/4/2010 15:31 <00000> 0x0001 0x0010 0x0014 0x0000 0x0144 0x0001 0x0001 0x0000 0x028F 0x2009 0x0105 0x00A9 0x005C 0xFA8C 0xFACC 0xFAF0 0x003B 0xFFA3

clear all;
%

[b,pathb]=uigetfile({‘*.txt’},’Select the file’,’C:\Data\2010′);

file2=[pathb b];

data=dlmread(‘file2’, ‘\t’, 2, 1);

newdata=hex2dec(data);

Now I do not know how to get rid of 0x in all the values and I need to convert the last column into binary and write in 8 columns.

Any help is highly appreciated.
thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T10:39:44+00:00Added an answer on May 18, 2026 at 10:39 am

    Here’s a slightly different tack you could try, using TEXTSCAN to read all the data first as strings:

    fid = fopen(file2,'rt');                   %# Open the file
    str = ['%s %s %s ' repmat('0x%s ',1,24)];  %# Format string for columns
    C = textscan(fid,str,'CollectOutput',1);   %# Read all fields as strings
                                               %#   (removing 0x's)
    fclose(fid);                               %# Close the file
    C = C{1};                                  %# Remove outer cell encapsulation
    
    dates = strcat(C(:,1),{' '},C(:,2));         %# Collect the date strings
    decValues = cellfun(@hex2dec,C(:,4:end-1));  %# Convert the first 23 columns to
                                                 %#   decimal values
    decValues = decValues-65536.*(decValues > 32767);  %# Change from unsigned to
                                                       %#   signed 16 bit values
    binValues = cellfun(@(n) dec2bin(hex2dec(n),8),...    %# Convert the last column
                        C(:,end),'UniformOutput',false);  %#   to binary strings
    

    If you have N rows in your file, you should end up with:

    • An N-by-1 cell array dates of date strings (which can be converted to either serial date numbers or date vectors).
    • An N-by-23 array decValues containing the converted decimal values. The values were converted from the range 0 to 65535 (i.e. unsigned 16-bit integer) to -32768 to 32767 (i.e. signed 16-bit integer) using two’s complement.
    • An N-by-1 cell array binValues containing the converted binary values. Each cell contains a 1-by-8 character string of zeroes and ones.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a config file which has some key value pairs
I am trying to read a file which has several lines and print it
I'm trying to read a txt file from a ftp server and I'm getting
I'm trying to read from a file called quiz_questions.txt in my res/raw folder. The
I am trying to read data (which is actually an array) in Lisp from
I am trying to read a text file which is set in CLASSPATH system
Okay so I've managed to read in a .txt file... now I'm trying to
I am trying to read a file which I read previously successfully. I am
I'm trying to read a file which is encoded in ISO-8859(ansi), and it contains
Trying to read headers for a csv file with: reader = csv.DictReader(open(PATH_FILE),skipinitialspace=True) headers =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.