Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[MOVED] My function to convert decimal numbers into binary numbers using Matlab

Status
Not open for further replies.

vickyuet

Member level 2
Joined
Oct 3, 2006
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
pakistan
Activity points
1,691
To convert numbers ,I had written my own function in Matlab instead of dec2bin or bin2dec(because it returns strings).I had checked it for many test cases and found it working.Can any body confirm, it works for all the valid test cases.I mean to cater any logical mistake at this stage because I need to apply it for large chunk of data.....for which verifying the accuracy will be difficult... valuable suggestions for improvement required...


function [out]=my_dec2bin( num )

num = round (num) ; % To ensure an integer number is entered
[f , len_num]=log2(max(num)) % log computes bits required for representation of max decimal value

for i=1:len_num

if num < 0
error('Number must be positive');
elseif num >= 1
remainder(1,i) = rem ( num , 2)
num = fix(num / 2); % convert it 2 integer again after division
end

end
out = fliplr(remainder(1 , :)); % flip to get right answer
end % function ends here....
 

Re: My function to convert decimal numbers into binary numbers using Matlab

hi! im new with MATLAB. and i really find it hard to understand the commands you've used. but i already tried that and it works perfectly. could you please explain it a bit more? (i dont know what those f, len_num and fliplr means :???: ) thanks in advance!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top