How to implement this in matlab?

Discussion in 'Programmer's Corner' started by tojeena, Aug 7, 2013.

  1. tojeena

    Thread Starter Active Member

    May 2, 2009
    118
    0
    How to implement this in matlab?
    n=1011(binary) 11 in decimal and b= 3(decimal) and finally getting answer as 011(binary).the b LSB of n to produce the subexponential code of n.How to implement it in matlab?
    n=1011 b=3 z=1|011 ans=011.What will be the program for this in matlab .?
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,431
    3,360
    Here are some ideas:

    Code ( (Unknown Language)):
    1.  
    2. %convert n to binary
    3.  
    4. dec = [ 1000 100 10 1];
    5. bin = [ 8 4 2 1];
    6.  
    7. n = 1011;
    8. s = num2str(n);
    9. b = [str2num(s(1)) str2num(s(2)) str2num(s(3)) str2num(s(4))];
    10.  
    11. sum(b.*dec)
    12.  
    13. sum(b.*bin)
    14.  
    15.  
     
Loading...