Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > convert NSData to int

convert NSData to int
Thread Tools
bonanza
Fresh-Faced Recruit
Join Date: May 2007
Status: Offline
Reply With Quote
May 26, 2007, 09:07 AM
 
Hi,
i like to load a simple raw image file, the values in the raw-file are from 0 (black) to 255 (white)

NSData *d = [NSData dataWithContentsOfFile: string];
if(!d)
return NO;

int i=0;
const char *data = [d bytes];
while(i< (size*size))
{
NSLog(@"DATA: %d", data[i]);
i++;
}
i have a sample image with the values 255,0,127..., but i get the Output -1,0,92.
Anyone know whats wrong with my snippet??
When i save back the data, the Image looks ok.
     
itai195
Addicted to MacNN
Join Date: May 2001
Location: Cupertino, CA
Status: Offline
Reply With Quote
May 26, 2007, 01:15 PM
 
You need to declare your array as unsigned chars. A lot of compilers consider chars signed...
     
bonanza  (op)
Fresh-Faced Recruit
Join Date: May 2007
Status: Offline
Reply With Quote
May 27, 2007, 01:53 AM
 
Originally Posted by itai195 View Post
You need to declare your array as unsigned chars. A lot of compilers consider chars signed...
thanks for reply.
this works better:
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 01:43 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,