GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ByteConvert_cpp/test/block_to_hex_string.cpp at master · fcccode/ByteConvert_cpp

Expand file tree

/

block_to_hex_string.cpp

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
46 lines (37 loc) · 1.32 KB
/

block_to_hex_string.cpp

Copy path

File metadata and controls

46 lines (37 loc) · 1.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <sstream>
#include <ByteConvert/ByteConvert.hpp>
int main()
{
std::cout << "Testing block_to_hex_string function" << std::endl;
// Generate all posible values for 1 byte
std::cout << "Generating all posibilities" << std::endl;
std::vector<std::pair<uint8_t, std::string>> test_values;
test_values.reserve(256);
std::stringstream ss("");
for (uint8_t i = 0; i <= 0xff; i++) {
ss << std::hex << unsigned(i);
test_values.push_back(std::make_pair(i,(ss.str().size()==2)? ss.str() : "0" + ss.str()));
ss.str("");
if (i == 0xff)
break;
}
// Test function
std::cout << "Testing" << std::endl;
std::string value("");
for (uint8_t i = 0; i < 0xff;i++) {
uint8_t block[2] = {test_values[(int)i].first,test_values[((int)i)+1].first};
value = ByteConvert::block_to_hex_string(block,2);
if (value != (test_values[(int)i].second + test_values[((int)i)+1].second)) {
std::cout << "Expected: " << (test_values[(int)i].second + test_values[((int)i)+1].second) << " Got: " << value << std::endl;
return -1;
}
if (i == 0xff)
break;
}
std::cout << "Done" << std::endl;
return 0;
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.