Ah, I should make a caveat to the code I posted earlier: that converts the integer to four bytes in little-endian format.
Assuming that you're running on an x86/x64 machine, I THINK the two bits of code are equivalent, but converting an int to a char pointer isn't the usual way of doing that (normally you'd just pass a pointer to an integer into whatever stream or data you're writing to and the conversion gets done automatically). But if you run both bits of code side-by-side on a Mac, you'll get different results. The code to convert an integer to bytes on a Mac is similar to what I posted earlier, but I don't know what the exact code would be (all of my data formats are little-endian, even on OSX).
The better way of doing it depends on your requirements. If you're looking for simplicity, use the pointer conversion. If you want cross-platform compatibility, do it the long way.
Not sure what you mean by "get a new int with the value," but assuming you mean to convert the bytes back into an integer (again, assuming little-endian):
Code:
int n = (((b[0] | (b[1] << 8)) | (b[2] << 16)) | (b[3] << 24));