Other positional number systems exist, such as binary, which work along the same positional principle, just with a different base. For example, binary has a base of 2, because computer bits can be one of two values; 0 or 1. Hexadecimal uses a base of 16, which means it needs to borrow letters to represent its numerals above 10.
Apart from the slight complication of sometimes having to interpret new symbols, different number systems are fairly easy to convert between. In each system, the general rule for determining value of a positional number system is total value = sum of each digit * the base ^ the digits position. For example, 543 in decimal...
543 = (5*10^2) + (4*10^1) + (4*10^0).
Matlab includes some functions for converting between different bases. Here are alternative versions of these functions and introductions to each system and the conversion processes:
- Converting hexadecimal to decimal - hex2dec2.m
- Converting hexadecimal to binary - hex2bin2.m - this function uses a slightly different approach to the others by using a lookup table. It can be adapted to do alternative conversions without having to worry about the underlying process.
- Converting decimal to binary - dec2bin2.m
- Converting decimal binary to decimal - bin2dec2.m
No comments:
Post a Comment