No announcement yet.

How to know if values is unsigned long?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How to know if values is unsigned long?

    How to know if is values entered from keyboard is unsigned long values?
    - only character with ascii (0x30 until 0x39) is allowed, with range 0 until 0xFFFFFFFF
    - negative value and symbol character is not allowed.

    If -1 entered from keyboard, I get price[0] := 0xFFFF and price[1] := 0xFFFF
    if -2 entered from keyboard, I get price[0] := 0xFFFE and price[1] := 0xFFFF

    Why negative value equal to positive values? -1 equal with 4294967295. This makes me confused.

    func isValidPrice(var *msg)
        var *p;
        var price[2];
        var n;
        var buf[10];
        p := str_Ptr(msg);
        while(str_GetD(&p, &price[n]) != 0) n += 2;
        to(buf); print([HEX4]price[0]," ", [HEX4]price[1]); // 0 until 0xFFFFFFFF allowed
    end func
    Thank You.
    Last edited by rwin; 28th July 2015, 04:41 AM.

  • #2
    In your keyboard routine you could prevent more than 4 digits being entered to keep the number to 16 bits, of course if you need the 10000 to 65535 then you can do a 'test' converseion and ensure that price[1] is 0.

    Binary numbers can be signed or unsigned if a 32 bit binary number is 0xffffffff is signed it is -1, if it is unsigned it is 4294967295

    This is basic stuff, try Dr. Google if you are still confused.


    • rwin
      rwin commented
      Editing a comment
      @Mark, Thank you for point out.