Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert decimal to binary, decimal to hex This function inputs a positive integer in decimal, and outputs an array (vector)with hexadecimal digits long dec_hex(long a,

image text in transcribed
Convert decimal to binary, decimal to hex This function inputs a positive integer in decimal, and outputs an array (vector)with hexadecimal digits long dec_hex(long a, std: : vector & digits) { const long base = 16: char alphanum[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}: digits.clear(): if (a 0) { long run = a % base: char c = alphanun[run] digits.push_back(c): a /=base: } std: : reverse(digits.begin(), digits, end()): // reverse the digits return 0: } Note that the output vector is 'char' not 'int' because the digits are alphanumeric. Safety check: if a & digits) Convert decimal to binary, decimal to hex This function inputs a positive integer in decimal, and outputs an array (vector)with hexadecimal digits long dec_hex(long a, std: : vector & digits) { const long base = 16: char alphanum[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}: digits.clear(): if (a 0) { long run = a % base: char c = alphanun[run] digits.push_back(c): a /=base: } std: : reverse(digits.begin(), digits, end()): // reverse the digits return 0: } Note that the output vector is 'char' not 'int' because the digits are alphanumeric. Safety check: if a & digits)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

5. Check on your expectations:

Answered: 1 week ago

Question

=+8. Why is productivity important?

Answered: 1 week ago

Question

=+ 9. What is inflation and what causes it?

Answered: 1 week ago