Problem in reading binary data from excel file

10 views (last 30 days)
I have an excel file that contains binary data in single cell. The binary data that is stored in excel is given below 1000111111001010000000
I am trying to read data in excel file using command
num = xlsread('abs.xlsx');
The data that is stored in num varialbe is 1.0001e+21. When i try to expands e+21 using command
num_Bin = sprintf('%23.0f',num);
it returns value of 1000111111001009900000 which is not a binary number. Can someone please tell me what's the problem with it?
  2 Comments
Image Analyst
Image Analyst on 4 Jul 2015
Unfortunately you forgot to attach abs.xlsx so probably no one is going to check out anything for you.
Sajid Khan
Sajid Khan on 4 Jul 2015
I don't need to attach abc.xlsx file I guess. Because the only thing that is in that file is binary value 1000111111001010000000
By the way here is attached file.

Sign in to comment.

Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 4 Jul 2015
1.0001e+21 is not also a binary number. Before importing your xlsx file, change the format of your cells to text.
  2 Comments
Sajid Khan
Sajid Khan on 4 Jul 2015
I have already changed format of my cell from "General" to "Number" in excel file. The value that is in my excel file is 1000111111001010000000 . Is there anyway I can read them as they are. I mean whenever I try to read binary values in excel file using command
num = xlsread('abs.xlsx')
it makes num as a double data type variable and it's in exponential form. I have to change them into non-exponential form by using statement
num_Bin = sprintf('%23.0f',num);
it works for most of the binary values but not on the given binary value of 1000111111001010000000.

Sign in to comment.


Image Analyst
Image Analyst on 4 Jul 2015
That is a decimal number, not a binary number. To get a binary number like you're thinking of it, you need to put a single or double quote symbol in front of it so that Excel will treat it as a string. Then you can do
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1};

Image Analyst
Image Analyst on 4 Jul 2015
OK, see my expanded explanation/solution:
% If you have a ' or " in front of the string in Excel
% so Excel knows it's a string and not a decimal number, do this:
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1}
% If you DO NOT have a ' or " in front of the string in Excel
% so Excel thinks 1000111111001010000000 is a decimal number
% of 1.00011111100101e+21 , do this:
[numbers, strings, raw] = xlsread('abc.xlsx');
binaryString = raw{1,1}
% IMPORTANT NOTE 1000111111001010000000 is the decimal number
% and will not still look like 1000111111001010000000 (the same)
% once it is converted into a binary string.
% Just like 101 (a hundred and 1) looks like
% 1100101 when converted into binary, not 101
% which you'd get if the number were 5, not 101.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!