CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 22

Thread: 24 bit integer

Threaded View

  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    24 bit integer

    Anybody got any ideas about how I could implement 24 bit integer types? For example, with some compilers I've seen things like:-

    typedef long long int Int64;
    typedef unsigned long long int UInt64;

    which are used for 64 bit types, but I want 24 bit types (3 bytes). I'd want to be able to do normal maths with them (plus, minus, multiply, divide etc) and assign values such as:-

    UInt32 x = 24117248; // 0x1700000 (this overflows a 24 bit Uint)
    UInt24 y = x; // result would equal 7340032 (0x700000) which is within range.

    [Edit]
    Ideally, they should also be capable of being cast to any of the other integer types - e.g.

    Code:
    Int32 SomeFuncThatRequiresA16BitInt ( Int16 n )
    {
    	return (n * 65536);
    }
    
    Int24 x = 29;
    
    Int32 y = SomeFuncThatRequiresA16BitInt ((Int16) x );
    Last edited by John E; March 20th, 2004 at 06:36 AM.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured