Thread: Divide 64bit number

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    20

    Divide 64bit number

    Hi,
    I want to divide a 64 bit value. I have a struct as following:
    Code:
    struct T
    {
       uint32_t high32;
       uint32_t low32;
    };
    And in for example in my main:
    Code:
    main()
    {
       struct T value;
    
       ...
       get a value for T
        ...
       
      HERE I WANT to divide the value by say for ex. 1000.
    }
    Is there anyway fast/ simple algorithm to do it? I don't want to loop with while and determine the division.

    Thanks,

    Inderjit

  2. #2
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    What compiler?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  3. #3
    Registered User
    Join Date
    Apr 2007
    Posts
    20
    gcc with nesc 1.1.3.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    How aboute:
    Code:
    union T
    {
       struct {
          uint32_t high32;
          uint32_t low32;
       };
       long long ll;
    };
    T t;
    ...

    t.ll /= 1000;
    ...
    [/code]

    --
    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.

  5. #5
    Registered User
    Join Date
    Apr 2007
    Posts
    20
    Thanks, it works!

    Inderjit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf oddities
    By robwhit in forum C Programming
    Replies: 5
    Last Post: 09-22-2007, 01:03 AM
  2. Finding a number within a number
    By jeev2005 in forum C Programming
    Replies: 2
    Last Post: 01-10-2006, 08:57 PM
  3. Prime number program problem
    By Guti14 in forum C Programming
    Replies: 11
    Last Post: 08-06-2004, 04:25 AM
  4. parsing a number
    By juancardenas in forum C Programming
    Replies: 1
    Last Post: 02-19-2003, 01:10 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM