Created
July 28, 2017 09:41
-
-
Save thejsa/07fd0a5c91ea55a797a39256550a7eff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* binaryadd.cpp (C++11) | |
* Adds two numbers and returns the results in hexadecimal | |
* Usage: binaryadd <0xHEX|0octal|decimal> <0xHEX|0octal|decimal> | |
* | |
* Copyright © 2017 thejsa <https://github.com/thejsa> | |
* | |
* This program is free software. It comes without any warranty, to | |
* the extent permitted by applicable law. You can redistribute it | |
* and/or modify it under the terms of the Do What The Fuck You Want | |
* To Public License, Version 2, as published by Sam Hocevar. | |
* See http://www.wtfpl.net/ for more details. | |
*/ | |
#include "stdafx.h" | |
#include <iostream> | |
#include <string> | |
#include <iomanip> | |
using namespace std; | |
int main(int argc, char* argv[]) | |
{ | |
if(argc != 3) | |
{ | |
cerr << "usage: " << argv[0] << " <number>" << " <number>" << '\n'; | |
return 64; // EX_USAGE | |
} | |
unsigned long i1, i2 = 0; | |
try | |
{ | |
i1 = stoul(argv[1], nullptr, 0); | |
i2 = stoul(argv[2], nullptr, 0); | |
} | |
catch(const std::invalid_argument& ia) | |
{ | |
cerr << "Invalid argument: " << ia.what() << '\n'; | |
return 65; // EX_DATAERR | |
} | |
unsigned long out = i1 + i2; | |
cout << "0x" << std::uppercase << std::hex << out; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much for this!
I'll be including
binaryadd.exe
in TWLIt in a future release.