[ create a new paste ] login | about

Link: http://codepad.org/d8roEuBP    [ raw code | fork ]

C++, pasted on Nov 9:
#include <string>
#include <vector>
#include <algorithm>
#include <cassert>

int parseHex(const std::string &num){
  std::stringstream ss(num);
  ss << std::hex;
  int n;
  ss >> n;

  return n;
}


int main(){


    assert( uint8_t( parseHex( "00" ) ) == uint8_t(0) );
    assert( uint8_t( parseHex( "01" ) ) == uint8_t(1) );
    //...
    assert( uint8_t( parseHex( "ff" ) ) == uint8_t(255) );


  uint8_t tgt_mac[6] = {0, 0, 0, 0, 0, 0};
  std::string v[] = { "00", "aa", "bc", "04", "05" };
  std::transform( v, v + sizeof(v)/sizeof(v[0]), tgt_mac, &parseHex );

//  std::copy( tgt_mac, tgt_mac + sizeof( tgt_mac )/sizeof( tgt_mac[0] ),
//    std::ostream_iterator<uint8_t>( std::cout, ":" ) );
}


Output:
No errors or program output.


Create a new paste based on this one


Comments: