I strongly suggest reading this as it covers the mathematical processes to convert in more detail than I’m going to. The conversion process itself is explained on Wikipedia. This code is written in a way to make the processes of conversion as clear as possible - it's all done with loops, which isn't technically the best way, but it serves a purpose here! Conversely my bin2dec string doesn’t require a string as an input, which is convenient for certain applications. There are a couple of difference between my scripts and MATLABs, for example my dec2bin2 function automatically buffers the output to 8 bits in the form of a vector rather than a string. ![]() ![]() Looking at the code in MATLABs functions is pretty fruitless for the latter. MATLAB already contains two functions to do convert between binary and decimal (dec2bin and bin2dec) but I wanted to write my own as a learning exercise – both in scripting and to learn the actual conversion method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |