移位验证小工具

#include 
#include 
#include 
  
void usage(char **argv);

int main(int argc, char** argv) {
  int opt = 0;
  int left = 0;
  while ((opt = getopt(argc, argv, "hl:")) != -1) {
    switch(opt) {
      case 'l':
        left = atoi(optarg);
        break;
      case 'h':
      default:
        usage(argv);
        exit(1);
    }
  }
  unsigned char val = 0x01;
  std::cout << std::hex << " 1 << " << left << " = 0x" << (val << left) << std::endl;
  return 0;
}
void usage(char **argv) {
  std::cout << "Usage: " << argv[0] << " \n"
            << "Options:\n"
            << "\t-h, --help\t\tShow this help message\n"
            << "\t-l, --left VALUE\tSpecify the shift left value"
            << std::endl;
}

你可能感兴趣的:(UNIX)