Reading binary decimals

ahed4ahed4 Member Posts: 21
What i was wondering for months now:
Has any of you an idea how i could use navision to read a 4-byte unsigned decimal (Single type in C# / C) with Navision? Reading a "Decimal" out of a binary file with Navision gets me nowhere - i guess nav has its own format. I cannot immagine doing it another way than reading a Binary and parsing an IEEE single out of it .. but then again: How in the world do you accomplish a SHL or SHR (shift-left, shift-right) in Navision?
I'm pretty stuck here ...
The freaks come out at night.

Comments

  • kinekine Member Posts: 12,562
    SHL - Value * 2
    SHR - Value DIV 2

    Integer in NAV is 4byte but signed. You can load any Integer value from file when in binary mode is used on the file. Than you just needs to work with the sign bit correctly.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ahed4ahed4 Member Posts: 21
    Sorry, i meant that i wan't to read a decimal value. However ... I cannot remeber that Navision supports SHL and SHR? Wait a minute ... Right. SHL and SHR are NOT supported by Navision. That is my main problem...

    Furthermore: Navsion does not allow AND and OR to be performed on Integeres / Decimals.

    I guess i have to deal with some automations to get this working ... Any suggestions?
    The freaks come out at night.
  • kinekine Member Posts: 12,562
    Have you read my post?

    Once again:
    Shift Left = Value * 2
    Shift Right = Value DIV 2

    BitOr(A : Integer;B : Integer) : Integer
    Pos :=1;
    Tmp := 0;
    MaxBit := 32;
    FOR i:=1 TO MaxBit DO BEGIN
      IF ((A MOD 2) =1) OR ((B MOD 2)=1) THEN
        Tmp := Tmp + Pos;
      Pos := Pos * 2;
      A := A DIV 2;
      B := B DIV 2;
    END;
    EXIT(Tmp);
    

    You can modify it for bit AND just by replacing OR in the condition by AND.

    Easy, isn't it? All bit operations are just math...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • ahed4ahed4 Member Posts: 21
    Oh sorry ... now I got it ...
    I guess that should do it ... I'll have a try.
    Thanks a lot!
    The freaks come out at night.
Sign In or Register to comment.