incomplete sequence

Hi all,
try this
unsigned char x1, x2, x3;
size_t ix = 0;
size_t count;
std::string Input = "EFEF9E9475C8C2D938C204EAE058F2B3";
unsigned char out[16];
for ( count = 0; count < Input.size(); count++)
{
x1 = Input[count++] & 0x4f;
x2 = Input[count] & 0x4f;
if (x1 & 0x40)
x1 -= 0x37;
if (x2 & 0x40)
x2 -= 0x37;
x3 = x1 << 4; /// First nybble
x3 |= x2; /// Second nybble
out[ix] = x3;
ix++;
}

when debug and have a watch on out i get incomplete sequence,
cant see whats wrong.

appreciate any help.
/huvcbo
IT would help if you described what you're trying to do.
OK

try to compress 32 byte of hex data and converts it to 16 bytes of binary data.
/huvcbo
Just make is less complicated:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <ctype.h> // isdigit, toupper

using namespace std;

int main()
{
std::string Input = "EFEF9E9475C8C2D938C204EAE058F2B3";
unsigned char out[16] = {0};
for ( size_t count = 0; count < Input.size(); count++)
{
  out[count/2] <<= 4;
  char value = 0;
  if(isdigit(Input[count]))
    value = Input[count] - '0';
  else
    value = 10 + toupper(Input[count]) - 'A';
  if((value >= 0) && (value < 16))
    out[count/2] += value;
}
	return 0;
}
Last edited on
thanks,
but i still get <incomplete sequence> when watch out in debug,
/huvcbo
In what way is my code coplicated?
Because of your use of magic numbers, it's not obvious that
1
2
if (x1 & 0x40)
  x1 -= 0x37;

is the same as
1
2
if(isdigit(Input[count]))
  value = Input[count] - '0';
OK, agree,
but whatever i get this <incomplete sequence> and I can not find a solution.

You see that because the sequence is not null terminated.
Topic archived. No new replies allowed.