This is the 29th day of my participation in Gwen Challenge

In the usual debugging code often need to the data conversion, in order to facilitate debugging. When data is low, you can use the computer’s own calculator to observe.

Open the system’s own calculator and select Programmer mode.

Through the conversion function of the calculator, you can see the values of different bases directly. If you have a lot of data, it’s too cumbersome to use a calculator. Then you can use the formula in excel to do the conversion.

Here’s how to use formulas to convert data formats in Excel.

Create a new table

Enter hexadecimal data in column A, binary data in column B, octal data in column C, and hexadecimal data in column D.

Then enter the formula “=DEC2BIN(A2)” in cell B2.

DEC means Decimal, BIN means Binary, and DEC2BIN means Decimal to Binary. This formula is easy to remember if English is familiar.

After the formula is entered, select A2 cell and place the mouse pointer at the lower right corner of A2 cell. When the mouse pointer changes to a plus sign, hold down the left mouse button and drag the pointer directly downward.

This converts a decimal number to a binary number. To convert decimal numbers to octal numbers, enter the formula “=DEC2OCT(A2)” in the C2 cell and “=DEC2HEX(A2)” in the D2 cell for converting decimal numbers to hexadecimal numbers.

The result after the transformation is complete is as follows

The formula works the other way around if the other base is converted to decimal.

Binary conversion to other bases

Octal is converted to another base

Conversion of hexadecimal to another base

In this way, when the amount of data is relatively large, the data format can be easily converted through the formula in the Excel table.

If you want the converted base to display in a fixed number of digits, you can add an argument to the =DEC2BIN function. The second argument is the number of digits to display.

For example, binary data is now displayed in a fixed 8-bit format. The formula sets the value =DEC2BIN(A2,8), and the binary number is displayed in a fixed 8-bit format.

The binary number is then displayed at a fixed width of 8 bits.

This through a simple tool can realize batch data format conversion, at the time of debugging MCU program, especially when debugging communication, transmission of the data is in hexadecimal format, direct reading up more trouble, so you can through the way of this batch conversion, the data converted to decimal format. It will be more convenient to read.