3

I'm using the NTL library to implement my code and I have to ZZ number which I have to convert to binary then take a substring from it and convert that substring into decimal. How can I do that?

ZZ N;
unsigned char pp[200];
BytesFromZZ(pp,N,NumBits(N));

The above code is giving me this error: "Segmentation fault (core dumped)"

EDIT : Above code is working now but instead of giving octal string it is returning garbage values.

Pratibha
  • 1,730
  • 7
  • 27
  • 46

2 Answers2

1

You should use NumBytes, and a result is a reversed string.

Philipp Grigoryev
  • 1,985
  • 3
  • 17
  • 23
1

The array pp which holds the byte-representation of N must be allocated with size equal to NumBytes(N). Otherwise, you get a SegFault if the length of pp is less than NumBytes(N). In addition, probably because of the Little-Endianess of Intel CPUs, pp represents N as a byte-string in reversed order.

ZZ N;
// assigning whatever value to N
unsigned char* pp = new unsigned char[NumBytes(N)];
BytesFromZZ(pp, N, NumBytes(N)); // pp = byte-representation of N
delete[] pp;
nam_ngn
  • 79
  • 4