Combine the output of multiple values

Posted on 2006-05-09
Last Modified: 2010-04-17
Dear Expert;

In c# .NET I need to combine the following values to create a unique inventory control number for a product.  The method must:

Get 2 digit Plant number from Table “PLANTMASTER” WHERE  “currentLocation” = 1
Get 2 digit year from system DATE/Time
Get Reader Number (a value of 1 digit located in Table “READERNUMBER” WHERE “currenReader = 1)
Get last ticket number (5 digits) from table and increment by one

Combine these values into value called newTicket and display it in the appropriate text box on a form.

I thought this would be easy enough but I am struggling wth it.

Thanks... Ed&Rosie
Question by:edrosie
    LVL 19

    Accepted Solution

    One thing you can do is use hex numbers and bit shifting.  For example, use a long integer as the value you want:


    Then, the 2 digit plant number could be like 0xA5

    The Year is another two digit hex number like 0x06

    One digit reader is 0x01

    Five digit ticket could be stored as a normal int:  0x004A

    Now, put these together like this:

    0x0000000000000000 | 0x004A to make the value 0x000000000000004A.
    Shift it left by 16 bits:
    0x000000000000004A << 16 which makes 0x00000000004A0000

    Now or it again with the next value which is the one digit reader value:
    0x00000000004A0000 | 0x01 and shift by 8 because you only need one byte this time
    0x00000000004A0001 << 8 is 0x00000000004A0100

    or the next value, the year for 0x00000000004A0100 | 0x06 = 0x00000000004A0106
    shift left by 8:

    Now do the last one:

    Now you have all your info stored in one number: 0x0000004A is the ticke number,
    0x04A, 0x01, and 0x06 are all available.  You can get to them by using the logical and:

    0x0000004A010600A5 & 0x0000FFFF00000000 will give you 0x0000004A00000000



    Author Comment

    thanks for responding so quickly.

    unfortunatly I have to use an existing format in order to coexist with the current system

    The existing format is 10 digits numeric

    example:  0806112345


    08 = plant number
    06 = year
    1 = reader number
    12345 = item number which must incriment by one each time a new ticket is created.

    Thanks for your help on this

    Author Comment

    Thank you for responding so quickly

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    INTRODUCTION We all know how to code. But at times you simply want to insert a common code block into your existing code and amend it as per your requirements. This tool not only saves you time but also saves you the pain of typing it all out aga…
    Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now