二进制表示法在计算机科学中很重要,计算机中存储的所有值都以一串二进制数字,即0和1的形式存在。 如果无法在通用表示形式和二进制数字之间来回转换,我们将需要以非常奇怪的方式与计算机进行交互。
十进制的数字如何转换成二进制的,举几个例子就明白了:图片来自https://www.geeksforgeeks.org/program-decimal-binary-conversion/
将17作为被除数,除以2,每次所得的余数有两种可能,0或者1. 最后将余数从先到后依次排列,即得到二进制代表的数。最高次的为MSB,最低次的为LSB. 图片来自https://www.geeksforgeeks.org/program-decimal-binary-conversion/
References:https://www.electronics-tutorials.ws/binary/bin_2.htmlwww.electronics-tutorials.ws
As the decimal number is a weighted number, converting from decimal to binary (base 10 to base 2) will also produce a weighted binary number with the right-hand most bit being the Least Significant Bit or LSB, and the left-hand most bit being the Most Significant Bit or MSB, and we can represent this as:
由于十进制数是一个加权数,因此从十进制到二进制(从10到2)的转换也将产生一个加权的