0

I am having problem inputting hexadecimal number using unsigned char array. Code:

unsigned char key[16];
for(int i = 0; i < 16; i++){
    cin>>key[i];
}

It takes single character as one character e.g. - 0x1b is read as 0 x 1 b separately. Please help me.

3
  • 1
    are you aware how many char are in 0x1b when you use the cin to give that input? Commented Jun 19, 2017 at 7:56
  • Please take the time to read How to Ask a question. In particular, please specify how it isn't working, what is intended and what is the result Commented Jun 19, 2017 at 8:18
  • There are 4 char in 0x1b and this code also takes it separately. Commented Jun 19, 2017 at 19:31

1 Answer 1

1

You can use std::hex.

unsigned int hex = 0;
for (int i = 0; i < 16; i++) {
    std::cin >> std::hex >> hex;
    key[i] = hex;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.