Problem in reading binary data from excel file
7 views (last 30 days)
Show older comments
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
on 4 Jul 2015
Unfortunately you forgot to attach abs.xlsx so probably no one is going to check out anything for you.
Answers (3)
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
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};
0 Comments
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.
0 Comments
See Also
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!