Value of unsigned binary??

Hi all, anybody know a way of getting an integer value from a binary? The binary represents a value in the range of 0-255, and i want to get this value. trouble is if you do a straight cast, it treats the binary as signed and returns a negative value for anything above 127. Does anybody know of an easy way to resolve this?
thanks,
J

ummm....simplest way is:
byte blah;
int bleh
/* do stuff and set value */
/* | */
/* a while later in code */
bleh = ((int)blah & 0x000000FF);
/* do more stuff */
/* | */
/* end of class,method,etc.*/

Similar Messages

  • DAQmxWrite​BinaryU16 not generating expected voltages from unsigned binary values

    Using DAQmxWriteBinaryU16, I observe the following output voltages
    with unsigned binary values :
    0 = 0V, 2047 = +10V, 2048 = -10V, 4095 = -4.8 mV
    I would have asumed that the unsigned binary range of 0 to 4095 would
    span the AO range of -10 V to +10 V respectively. Or that 0 = -10V,
    2047 = 0V, and 4095 = +10 V
    For DAQmxWriteBinaryI16, I observe 0 = 0V, 2047 = +10V, -2048 = -10V
    with signed binary values as expected

    Hello Steve,
    0 to 2047 is 0 to +10V
    2048 = -10V and it keeps decreasing to one step below 0 which is equal to 4096
    -Arun V

  • Select returns negative values for unsigned datatypes in MySQL DB

    Hi, I have a table in a MySQL database where some fields are declared as "unsigned".
    Example:
    CREATE TABLE countries (
    Country_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    Number SMALLINT UNSIGNED NOT NULL
    My problem is when inside a .xsql file, I try to do a select:
    <xsql:query>
    select Number from countries where Country_id="15"
    </xsql:query>
    If inside the Database, Number always goes from 0 to 65535 (UNSIGNED SMALLINT),
    the resulting XML of that query will always show negative values if Number is
    bigger than 32767 (so it ignores the "UNSIGNED").
    Have you seen something like this before? Do you kwno what I'm doing wrong or what
    can I do to retrieve the values unsigned?
    Thanks a lot!
    David

    hi muneer
    >
    We are facing a strange issue in our R12.1.3 Ebiz instance (DB 11.2.0.1) - Solaris Sparc 64 bit - 2 node (1 node Apps, 1 node DB).
    Some of the purchase orders are having a negative purchase order number.
    SQL> select segment1 from PO_HEADERS_ALL where segment1 < '0';
    SEGMENT1
    -7951814
    -8960847please see
    Error: Purchase Order Creation Could Not Be Initiated, But PO Was Created With Negative PO Number And No Distributions [ID 789464.1]     To Bottom     
    PO Creation Process Failed In Sourcing And Creates Document With Negative Numbers [ID 1479616.1]
    Purchase Order Receipt FAQ (P4312) [ID 1306869.1]
    How it could happen. Any suggestions please !looks like a bug
    Can a Purchase Order (PO) Be Created With Negative Quantity or Price? [ID 241389.1]
    AppsMasti
    Sharing is caring

  • How to read long&short value in a binary file written in C++?

     

    Double posted.
    Continue here:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=147257&start=0&range=100#416759

  • Wrtie unsigned char and unsigned int into a binary file

    Hi, I need write some data into some specific file format (.ov2) for other applications to read.
    Here is the requirement of the data:
    First byte: An unsigned char value, always "2" means simple POI entry
    Next 4 byte: An unsigned int value,
    Next 4 byte: A signed integer value.
    Next 4 byte: A signed integer value
    then next : A zero-terminated Ascii string
    Here is my code:
                       String name = "name";
                       byte type = 2;
                     int size = name.length() + 13 +1; //1+4+4+4 and there is a 0 at last
                     int a = 1;
                     int b =2;
                     ds.writeByte(type); //1 byte, need save it as unsigned char
                         ds.writeInt(size); //4 //need to be an unsignged int
                         ds.writeInt(ilont); //4 //signed int
                         ds.writeInt(ilatt); //4 //signed int
                         //write zero-terminated ascii string
                         for(int n=0; n<name.length(); n++){
                              ds.writeByte(name.charAt(n));
                         ds.writeByte(0);                    This code could not get the correct result and I think I must do some sign to unsign conversion, but I don't know how to do it. Any help?
    Thanks for you attention.

    You don't have to do anything special at all. What's in a int or a byte is what you, as a programmer, say it is. Java treats int's as signed but, in fact, with 2's complement arithmatic most operations are exactly the same. Load and store, add and subtract - it makes no difference whether a variable is signed or unsigned. It's only when you convert the number, for example to a wider type or to a string representation that you need to know the difference.
    When you read an unsigned byte and you want to widen it to an integer you have to clip the top bytes of the integer e.g.
    int len = input.get() & 0xff;This is because, since java sees a byte as signed it will extend the sign bit into the top bytes of the int. "& 0xff" forces them to zero.
    Writing it, you don't have to do anything special at all - it will autmatically get clipped. The above is probably the only concesion you'll ever need to make to unsigned binary. (You'd need to do the same thing from unsigned int to long, but this almost never happens).
    When I read ov2 files I used a mapped byte buffer, because it allows you to set either big-endian or little-endian and I wasn't sure which ov2 files used. (Sorry, I've forgotten).

  • Parsing binary file- unsigned longs

    Hello everyone.
    I'm currently trying to write a quick parser for a binary file format (ASF). However, java's handling of bit shifting and lack of unsigned types is driving me completely mad.
    How can I represent an unsigned long?
    How can I set the bits for it anyway? It seems that the shift operator can't shift more than an int's worth (it just loops around and starts adding to the other bits- weird).
    Thanks in advance.
    Simon

    ejp wrote:
    But why in the world does the following code also do nothing?
    long x = 45 << 32;
    Try long x = 45L << 32;
    The answer appears to be that java uses ints to represent all constants, but this presents some serious problems- namely- how on earth do you get a number bigger than an int into a long?With 'L'. Same as in C or C++. In Visual Basic it's '&'. There's generally something.Where did that come from? Why have I never seen anything like that before?
    If I do long x = 0x7FFFFFFF; all is well, but if I do long x = 0x80000000; I get FFFFFFFF80000000, which isn't what I asked for.Actually it is exactly what you asked for. You've overlooked several facts: (i) Java longs are 64 bits; (ii) you specified a negative 32-bit constant; (iii) the rules of every programming language I can think of provide for sign-extension when going from a shorter to a longer type.Right. It makes sense now that I know how to specify long constants.
    As someone pointed out signed/unsigned is actually the same, so long as you interpret it correctly. So to avoid the total stupidity of using twice as much memory for everything I've decided that I am actually going to use the correct types.They're not the correct types. As I pointed out in an earlier post, your 'unsigned longs' must be coming from C or C++ where they are generally 32 bits, so using a 64-bit Java long is incorrect.Where they came from doesn't matter. The spec doesn't say it's a "long"- it says that this particular value is 64bit, and that all values are unsigned. So I do need a Java long.
    WHY IN THE WORLD IS JAVA "INTELLIGENT" WHEN DOING THINGS BITWISE? WHICH BRAIN DEAD IDIOT THOUGHT THAT UP? That is broken and is asking for trouble.It is you who is asking for trouble here. The rules of Java are consistent and in conformity with the practice in other programming languages. You've just overlooked several relevant facts.I think I've worked out where I was going wrong here. When doing something like
    int i;
    long x;
    x = x | i;The i is converted to a long before the bitwise operation, so it's not the bitwise operation that's the problem, it's the conversion between int and long?
    It's not Java whose stupidity is the issue here ;-)That wouldn't surprise me.
    Thanks.

  • Unsigned bytes?

    I'm reading binary data as unsigned bytes but Java is insisting on using signed bytes (so when I try to use Byte.parseByte("88"), I get a NumberFormatException). I can't find anything in the API that looks like it'll do this for me. Help please!

    Bytes are always unsigned in Java.
    It's not clear what you're trying to do. First you say "binary data," then you say "parseByte," which would be used on textual data.
    If it's just bytes, then reading the bytes will give you the proper values. If you want to see those values as unsigned integers, so that 0xFF is 255, rather than -1, then you can do int ii = bb & 0xFF; Can you clarify what you're trying to do?

  • Converting a binary string to a number...

    Hi guys,
    I'm trying to convert a binary string into a decimal integer. I'm not sure if LabVIEW has a VI that does that. I haven't found one yet. Basically, say I have the string '0101'. I want to convert that to the value '5'. Or say I'm using hex, I want '10101111' to be converted to 'AF'. So that's my dilemma. I'm hoping I'm not going to have to make my own VI. Thanks a lot!
    -Mike

    LabVIEW has exactly what you want even if it can be hard to find it.
    To convert a binary text string like "0101" to a decimal value can easily be done using the Scan Value function found under the String/Number conversion section. If you provide the format %b to it (not mentioned in the manual) you will get the decimal value of your binary string.
    Also, on your front panel you can change the format of your numerical indicators by right clicking on it and selecting Format & Precision. If you have a numerical indicator you can set it do display the numbers in e.g. hexadecimal form.
    However, if you want to convert a number to a hexadecimal text string you can use the Number to Hexadecimal String function also found under the String/Number conversion section.
    I
    attached a simple example, Conversions.vi, that shows how it works. I hope this helps. /Mikael
    Attachments:
    conversions.vi ‏14 KB

  • How to extract a field from Binary object

    Hi Guys,
    I have a Binary object in custom aggregator and I would like to extract a field from the Binary object without de-serializing the Binary object. I know this can be done but figure out how.. Appreciate your help.
    Have tried this
    PofValue value = PofValueParser.parse(Binary, (PofContext) BinaryEntry.getSerializer());
    PofValue child = value.getChild(1);
    Object value = child1.getValue();
    but no luck.
    Thanks
    D

    Hi JK,
    Thanks..  I have Binary  and tried
    PofValue pofValue = PofValueParser.parse(binary, pofContext);
    PofNavigator path = new SimplePofPath(1);
    PofValue target = path.navigate(pofValue);
    Object value = target != null ? target.getValue() : null;
    but no luck.. I must be missing something.
    Basically, am trying to do cache joins using aggregator and data affinity. Sample code snippet
    @Override
      public Object aggregate(Set values) {
      List extractedValues = new ArrayList();
      for (Map.Entry entry : (Set<Map.Entry>)values) { 
       try {
        //these are BinaryEntries in TESTCACHE1
        BinaryEntry binaryEntry = (BinaryEntry)entry;  
        Long compId = (Long)binaryEntry.extract(new KeyExtractor("getComponentId")); 
        Long contId = (Long)binaryEntry.extract(new KeyExtractor("getPartyId"));
        BackingMapContext backingMapContext = binaryEntry.getContext().getBackingMapContext("TESTCACHE2");  
        ObservableMap backingMap = backingMapContext.getBackingMap();
        MapIndex mapIndex = backingMapContext.getIndexMap().get(new KeyExtractor("getComponentId"));   
        com.tangosol.util.InflatableSet keySet = (com.tangosol.util.InflatableSet) mapIndex.getIndexContents().get(compId);
        Binary object = null;
        for(Object key : keySet ) { 
         object = (Binary)backingMap.get(key);    
        PofNavigator  path  = new SimplePofPath(2);
        PofValue value = PofValueParser.parse(object,  (PofContext) binaryEntry.getSerializer());
        PofValue  target = path.navigate(value);  
        Object extractedValue = target != null ? target.getValue(): null;
        extractedValues.add(extractedValue);
       } catch (Throwable t) {
        log.error("Exception in aggregate method ", t);
        throw new RuntimeException("Exception in aggregate method", t);
      return extractedValues;

  • Conversion from Binary to decimal - Need help

    Hi guys,
    I am new here and learnt some very basic Java before. I have a program that is in C++(to convert a binary number to decimal) that I found in the internet that interest me a lot. I am thinking whether this can be re-write in Java. I have tried to searh for solution but to no avail. I am wondering whether you guys can suggest a solution to this. Below are the source code in C++ :
    #include <iostream.h>
    #include <stdlib.h>
    int main()
    // part 1 : declaration
    int Bin, Dec, TempBin;
    int div;
    char valid, again;
    do {
    // part 2 : Repeat asking the value of the binary number
    Bin = TempBin = 0;
    do {
    cout << "Please input a binary number (1 to 10 bits) : ";
    cin >> Bin;
    TempBin = Bin;
    do {
    if ((TempBin % 10)==0 || (TempBin % 10)==1) // Note (1)
    valid='Y';
    else {
    cout << "Invalid pattern! use 0's and 1's only\n\n";
    valid='N';
    break;
    TempBin = (TempBin/10);
    } while (TempBin>0);
    } while (valid=='N');
    // part 3 : Convertion
    div = 1;
    Dec = 0;
    TempBin = Bin;
    do {
    Dec += (TempBin % 10)*div; // Note (2)
    div *= 2;
    TempBin = (TempBin/10);
    } while (TempBin>0);
    cout << "\nThe binary pattern " << Bin << " is equal to "
    << Dec << " in decimal pattern.\n" << endl;
    // part 4 : try another number ?
    cout << "\aTry another number (Y/N) : ";
    cin >> again;
    cout << "\n";
    } while (again=='Y' || again=='y');
    cout << "\n" << endl;
    system("PAUSE");
    return 0;
    Appreciate your help. Thank you.
    CK

    So for Java, in your example, it takes a Java
    String like "1001" and converts it to an int whose
    value is one thousand and one. Can suggest a code for
    this that takes user input str and convert to bin int.
    I read books and noticed they are various ways to do
    that. I am quite confused actually. It is like there
    is no fix way to do that, unlike C++ which is more
    easier to understand(in my opinion). Probably, because
    I knew C better than Java.
    The 'standard' way to take a String and convert it to an int...
    int TempBin=Integer.parseInt(your_string);
    You seem to be saying that you do not want to use the standard method, so you should not complain that there is no standard method. Here's some code that re-uses most of your modulo 10.
    import java.io.*;
    public class Test {
         public static void main(String []args) throws IOException {
              BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
              String result=null;
              while(true) {
                   String input=bf.readLine().trim();
                   try {
                        long v=Long.parseLong(input);
                        result=toBin(v);
                        System.out.println(result);
                   } catch(NumberFormatException e) {
                             System.out.println("Only enter 1 or 0, nothing else!");
                   System.out.println();
           public static String toBin(long btemp) {
              long temp=btemp;
              do {
                   if ((temp % 10)!=0 && (temp % 10)!=1) {
                        System.out.println("Invalid pattern! use 0's and 1's only\n\n");
                        return null;
                   temp = (temp/10);
              } while (temp>0);
              // part 3 : Convertion
              int div = 1;
              int Dec = 0;
              long TempBin = btemp;
              do {
                   Dec += (TempBin % 10)*div; // Note (2)
                   div *= 2;
                   TempBin = (TempBin/10);
              } while (TempBin>0);
              return ""+Dec;

  • Binary Search

    Hi SDN Experts
    Is it must to use a sort statement before we use a binary search in a read statement. because in some cases its failing as SY-SUBRC = 4 if my internal table is not sorted.
    Please confirm me
    Regards
    Pratyusha

    Hi,
    Yes, it is mandatory to sort the table before doing a binary search.
    The principle of binary search only work in case of sorted tables.
    A binary search algorithm is a technique for finding a particular value in a sorted list. A binary search finds the median element in a list, compares its value to the one you are searching for, and determines if it’s greater than, less than, or equal to the one you want. A guess that turns out to be too high becomes the new top of the list, and one too low the new bottom of the list. The binary search's next guess is halfway between the new list's top and bottom. Pursuing this strategy iteratively, it narrows the search by a factor 2 each time, and finds your value. A binary search is an example of a divide and conquer algorithm.
    More on binary search.
    The idea is to eliminate half of the search space with each comparison.
    First, the middle element of the sequence is compared to the value we are searching for. If this element matches the value we are searching for, we are done. If, however, the middle element is “less than” the value we are chosen for (as specified by the relation used to specify a total order over the set of elements), then we know that, if the value exists in the sequence, it must exist somewhere after the middle element. Therefore we can eliminate the first half of the sequence from our search and simply repeat the search in the exact same manner on the remaining half of the sequence. If, however, the value we are searching for comes before the middle element, then we repeat the search on the first half of the sequence.
    Hope this helps.
    Regards,
    Kate

  • How to convert binary string to ascii

    Hi,
    See i have a string like this,
    String str = "10011100110001011001110011000101";
    Now i want to find exact ascii value of the binary string.
    Thanks in advance.

    First want to convert these bits to corresponding
    characters and then have to find ascii of the same.... corresponding to what? I think converting these "bits" to the corresponding chars is the whole story. But what about the original format?
    Guessing mode on ... does this help?
    String input = "...";
    StringBuffer result = new StringBuffer();
    for (int i = 0;i < input.length();i += 8) {
      result.append((char) Integer.parseInt(input.substring(i, i + 8), 2));
    System.out.println(result);

  • Missing inverse index on remove: value=null

    When upgrading from Coherence 3.4 to 3.5 and during our test runs we see this in the log ..
    +12:56:39,241 INFO Coherence:3 - 2010-02-23 12:56:39.241 Oracle Coherence GE 3.5.3/465 <Info> (thread=dist-tradeobject-serviceWorker:1, member=17): Missing inverse index on remove: value=null, key=Binary(length=102, value=0x0DA20515AE0F00014E2C3130303232333A545955533A4275793A4571753A4D3A43534642444D413A5553443A5553443A435346423A30034E2C3130303232333A545955533A4275793A4571753A4D3A43534642444D413A5553443A5553443A435346423A3040)+
    above lines are repeated multiple times for multiple objects. Not sure what prompts this info message outcome..
    Can you please give me some pointers
    Thanks

    Hello,
    Sorry for the delay in responding. This does appear to be an issue which can be reproduced. There is an open issue number (COH-3055) assigned for tracking purposes. Thank you for reporting this problem.
    Dave

  • What does "Missing reverse index on remove: value=null" mean

    I am getting this error in my Coherence Debug Logs, what does this error mean ?
    Thanks
    14:46:24,923 WARN Coherence:3 - 2009-05-06 14:46:24.923 Oracle Coherence GE 3.4/405p1 <Warning> (thread=dist-customer-serviceWorker:1, member=25): Missing reverse index on remove: value=null,
    key=Binary(length=102, value=0x0DB53915AADDGFDF...etc

    I am still seeing this message (but as a info message) in 3.6.0.1. The test case is a single cache node and a single "client" that is inserting a lot of data. I have like 6 indexes defined (all using POF extractors). One index contains an array of a user type, the others primitive types. One index is sorted the rest not.
    Imho the condition causing this should be fixed or, if this is not causing any problems, performance or otherwise, the message be removed - pperation should be undisturbed by messages that has no meaning to the user!
    2010-08-19 08:42:57.718/50.860 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=432}, key=Binary(length=17, value=0x0DB30315A33E000041BC010141A5CC0140)
    2010-08-19 08:42:57.718/50.860 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=1117}, key=Binary(length=17, value=0x0DB40315A33E0000419B140141A4C40140)
    2010-08-19 08:42:57.718/50.860 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=3194}, key=Binary(length=17, value=0x0DB50315A33E0000419D2E0141A7CC0140)
    2010-08-19 08:42:57.734/50.876 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=542}, key=Binary(length=17, value=0x0DB90315A33E00004192450141BC900240)
    2010-08-19 08:42:57.734/50.876 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=4042}, key=Binary(length=17, value=0x0DBB0315A33E000041940A01419C890340)
    2010-08-19 08:42:57.734/50.876 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=4733}, key=Binary(length=17, value=0x0DBC0315A33E000041BC1D014191D90240)
    2010-08-19 08:42:57.734/50.876 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=1632}, key=Binary(length=17, value=0x0DBE0315A33E000041B43E0141B1D00140)
    2010-08-19 08:42:57.749/50.891 Oracle Coherence GE 3.6.0.1 <Info> (thread=DistributedCache, member=1): Missing inverse index: value=ObjKey{typeId=0, instanceId=2490}, key=Binary(length=17, value=0x0D800415A33E00004196310141BEFC0140)
    /Magnus

  • Group 8 channel (binary) to octal/hexa​decimal

    Hi,
    Let say I have 8 channel of binary data in array and plotted to the graph. If button "Grouping" pressed, then the 9th channel will be plotted, which is in octal value (Sum of binary value at the same sample).
    <Please refer to the picture attach>.
    I m using HSDIO 6552 to generate and acquisite the data, and I need to group some of the acquisited data.
    Problem:
    I don't know how to generate the 9th channel on the graph, as shown in the attached pic. So, I m seeking help on how to "Add" the octal-value channel. Any1.. pls help.. Thanks in advance.  
    Attachments:
    grouping.JPG ‏16 KB

    Hi engwei,
    One way to display it programmatically is to use property nodes. They allow you to change the visibility, data type, transition type, etc. of an active plot. To access the property nodes of a graph, right-click on it and select Create >> Property Node. Attached is a screenshot of a property node I used to change one of my graph plots. Let me know if you have any further questions, thanks!
    Cheers,
    Jonah
    Applications Engineer
    National Instruments
    Jonah Paul
    Marketing Manager, Embedded Software
    Evaluate the LabVIEW RIO Platform! - ni.com/rioeval
    Attachments:
    digital_waveform_octal.JPG ‏11 KB

Maybe you are looking for

  • Days of Credit field ?

    Hi all, I have a reqmt in which, I have to report Weighted Average days of vendor payment. <b>Selection parameters:</b> Company code range Vendor range Payment date range Payment document type. <b>Report columns:</b> Vendor # Vendor name Terms of pay

  • Geeting error while consuming webservice from java

    Issue description : We are tried to connect to clients SAP bapi web service with Apache Axis tool  ( version- axis2-1.5) and SOAP UI tool (SOAPUI3.6.1 )  , we faced following error : and getting following login error failed error from SAP. Error : HT

  • Unable to find images in Aperture 3

    I've tried finding a batch of images (all taken on the same date) via the calendar route with no success, is there a way to locate and transfer them to Aperture 3 so that they can be found in there? Where can I find the folder that has all the Apertu

  • How do you get a list of records to scroll automatically instead of page

    I have a set of records displayed in a list control. The list currently pages through the records and displays two records at a time. I want to display all the records and have them scroll vertically like movie credits and allow users to adjust the s

  • Validation for PAN number

    Dear all, We are entering PAN number as 10 characterstics, PAN number formate 1st five character are Alphabets next 4 are digits and last i.e 10th character is alphabet.(Ex ABCDE1234Z).some time USERS enter different characters not Original. Can we v