Thread: unsigned negative problem :s

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    1

    Unhappy unsigned negative problem :s

    i've written this code in which i read values from a binary(.dat) file. The file has got 2 sets of values. Index values(0-360) and the corresponding amplitude. The amplitude can be upto a 5 digit negative or positive number. I have defined the struct as foll:

    struct snip
    {
    int n;
    unsigned x;
    };


    for 'x' when i defined it as float or double it would'nt read the values properly, but when using unsigned, it works fine except that it does'nt read the negative values the way it is, instead the negatives values r stored as some really large number.....can some1 pleaseee heelp me out..........its is killing me tht i cant figure out wht to do,............

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Change unsigned to int, and I think you would be fine. That is how signed versus unsigned numbers work: An unsigned number is always positive. A signed number is negative if the highest value bit is set to 1 - which means that all negative values are very large positive integers when seen as unsigned.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. problem with reading and writing
    By yahn in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2006, 04:38 PM
  3. Problem with my file opener
    By kzar in forum C Programming
    Replies: 7
    Last Post: 04-20-2005, 04:20 PM
  4. Traceroute using UDP + ICMP
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 08-05-2002, 10:50 AM