移位验证小工具

来源:互联网 发布:网页翻译软件 编辑:程序博客网 时间:2024/05/21 12:45
#include <iostream>#include <unistd.h>#include <stdlib.h>  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] << "<options> \n"            << "Options:\n"            << "\t-h, --help\t\tShow this help message\n"            << "\t-l, --left VALUE\tSpecify the shift left value"            << std::endl;}

0 0
原创粉丝点击