Using C++ Programming to Perform Number System Conversions

Abstract

Carrying out number system conversions is one of the many things computers can be programmed to do. This report encapsulates the process of creating, testing, and reviewing my own number system conversion program using C++. Even while being limited to certain concepts, my program effectively calculated various conversions. However, it was found that incorporating more advanced structures could have made the program more readable and efficient.

Introduction

Numbers play an important role in our lives, especially to those who pursue an engineering occupation. And as there are a variety of engineering careers, there are a variety of number systems that we use. According to Jason Killian from Envato Tuts+, a number system is simply “a way to represent numbers” (Killian). For example, the binary number system is commonly used in programming, since computers are unable to understand words and numbers that we use in everyday communication (Heddings). Engineers who work with multiple number systems need to be able to convert from one system to the next. But since computing these conversions by hand is a strenuous task, we typically design programs that get the job done for us. Creating computer programs like this one is important because they help with “automating processes, collecting data, analyzing information and sharing knowledge to continuously innovate and improve upon existing processes” (“Why Is Programming Important?”). That said, this report presents the design of a number system conversion program using C++.

Materials and Methods

The Sublime Text text editor was used to write and store all of the C++ source code used for this program. In order to compile and execute the code, I made use of the terminal built into the Ubuntu operating system being used. This entire project was done within the virtual machine Oracle VM VirtualBox.

Results

The final project ended up having a total of 850 lines of code. The switch statements that were incorporated printed out the list of available conversions. A combination of for and while loops were also used frequently throughout the program. Most of the for loops printed out a series of equal signs (=) as a way to separate different sections of the program, and the while loops controlled various events, including whether or not the main program will continue running.

An example of a switch statement being used. This was responsible for printing out the options of the main menu. (Window: Sublime Text)

How the main menu is printed in the terminal. (Window: Ubuntu terminal)

An example of a number system conversion. In this image, the decimal number 1324 was converted into its binary equivalent. (Window: Ubuntu terminal)

Discussion

All of the conversions used in this program were executed successfully. However, I realized that the 850 lines of code that make up the program can be reduced after learning about more advanced concepts. One way to make this reduction is to incorporate several user-defined functions. For example, instead of repeatedly writing out long switch statements to print the menu, I could have instead put one switch statement in a function named PrintMenu() and call the function when necessary.

Conclusion

Working on this project was important because not only was I able to gain more experience with the programming language C++, but I designed something that can be useful in the real world. This version of a number system converter has a lot of room for improvement, but it is still effective.

Acknowledgments

I wish to express my appreciation to Prof. Motahare Mounesan, my Introduction to Computing professor, for her support during the making of this project. Not only was most of the code based on her resourceful lectures, but she was willing to answer any questions I had about the project.

References

Heddings, Anthony. “What Is Binary, and Why Do Computers Use It?” How-To Geek, 1 Oct. 2018, www.howtogeek.com/367621/what-is-binary-and-why-do-computers-use-it/.

Killian, Jason. “Number Systems: An Introduction to Binary, Hexadecimal, and More.” Envato Tuts+, 13 Feb. 2012, code.tutsplus.com/articles/number-systems-an-introduction-to-binary-hexadecimal-and-more–active-10848.

“Why Is Programming Important?” Grand Canyon University (GNU), 25 Sept. 2020, www.gcu.edu/blog/engineering-technology/computer-programming-importance.