#pragma once
#ifndef HEX #define HEX #endif
#include <string>
const std::string HEX_DIGITS {"0123456789ABCDEF"};
using namespace std;
std::string
anywhere we want a string.
int HexDigitToInt(char digit); char IntDigitToHex(int digit);
#include "Hex.h"
using namespace std;
std::string
everywhere.
HEX_DIGITS
using the string find function.
OBJS =
line
OBJS = Hex.o
all: ${OBJS}
all: ${OBJS} Hex.o: Hex.h
hexTest.cpp
OBJS = Hex.o
OBJS = hexTest
all: ${OBJS}
hexTest: Hex.o
std::string IntToHex(int number)
Initialize the return string to be blank. If the number is negative, note this and make the number positive. If the number is 0, set the return value to be "0" else while the number is greater than 0 digit = number % 16 add the digit as a hex digit to the front of the number. (use IntDigitToHex) number = number / 16 If the original number was negative add a negative sign to the string return the string.
int HexToInt(std::string number)
set value to 0 For i = the first valid digit to the last valid digit value = value * 16 + the the value of number[i]