| | |
hexadecimal.cpp
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
There might be something quite close in the Code Snippets.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Jul 2005
Posts: 10
Reputation:
Solved Threads: 0
Use modulus (this operator gets the remainder of a / b) 16 repeatedly to get your digits. Use a while loop while dividing the given number by 16 after modulus (use ints, you want truncation) until the given number becomes less than 16.
ie. You have a number, say 254.
254 % 16 = 14. This is your one's digit.
254 / 16 = 15.875 -> 15 after truncation.
15 % 15 = 15. This is your ten's digit.
As for digits, simply use an array of characters for simplicity. Add the characters to the front rather than the end, of course.
Edit: Whoops, not used to the reply tree here. My bad.
ie. You have a number, say 254.
254 % 16 = 14. This is your one's digit.
254 / 16 = 15.875 -> 15 after truncation.
15 % 15 = 15. This is your ten's digit.
As for digits, simply use an array of characters for simplicity. Add the characters to the front rather than the end, of course.
Edit: Whoops, not used to the reply tree here. My bad.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Again please someone check my code
- Next Thread: Messy array things.
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez graph homeworkhelp iamthwee ifstream input int java lib library lines list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sorting spoonfeeding string strings struct temperature template templates text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






