Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Permenkaret Permenkaret is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 351
Rep Power: 14
Permenkaret mempunyai hidup yang Normal
Default [help] binary Matlab

gan ane bkin program konversi biner to ASCII pake MATLAB... gini gan:



misal binernya : x = 011111010110001011000001101000010100



ane jadiin ASCII pake script ini


Quote:







t=length(x);

A=x;

[l m]=size(A);

for i=1:m

Data(:,i)=str2num(A(i));

end

hc=Data;



na='hasil.txt';

hasil=fopen(na,'w+');



for i=1:8:t

ck=t-i+1;

if(ck>8)

tp=(hc(i:i+7));

num=8;

else

tp=(hc(i:t));

num=ck;

end

temp1=b2d(tp,num);

temp2=char(temp1);

fprintf(hasil,'%c',temp2);

end

fclose(hasil);






ini file b2d.m


Quote:





function PW=b2d(tp,num)

PW=0;

j=0;

for i=num:-1:1

PW=PW+pow2(tp(i),j);

j=j+1;

end

return





ini hasilnya gan : }ba



nah ane balikin lagi ke biner




Quote:





nme='hasil.txt';

id = fopen(nme,'r');

a = fscanf(id,'%c',inf);

fclose(id);



[m,n]=size(a);

k=1;

for i=1:n

b(i)=double(a(i));

end



for i=1:n

c = dec2bin(b(i),8);

for j=1:8

d(k)=c(j);

k=k+1;

end

end

disp(d)





hasilnya : 0111110101100010110000011010000100000100



kelebihan 0 sebanyak 4... ada yg bisa gak cara ngatasinya... please!!!



Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 02:30 PM.


no new posts