jump to article
...intermittent thoughts

Binary Conversion using Val()

The other day I was playing around with number system conversions in LotusScript. It came to the point I was converting a 32 bit binary value to a decimal long. By defintion long is a 32bit signed integer value in LotusScript. That means the 32nd bit is used to inidcate if the number represents a positive or negative number. Knowing that I was pretty sure I only need to take care for the 32nd bit in the binary representation I wanted to convert:
Val ( "&b00000000000000001000000000000000" )

should return 32768.
My surprise was high when I got the result form that statement: -32768.
After sticking around for quite a bit of time, I realized this number is exactly the end of the Integer datatype representable number range. The LotusScript Integer datatype is defined to be a 2 bytes signed integer value, leading to a representable range from -32768 to 32768. Then it hit me. Val() seems to be trying to convert a number to the smallest fitting datatype and then returning it as a double value. In this particular case
Val ( "&b00000000000000001000000000000000" )

looks like requiring only the first 16 digits of the boolean value, that is only two bytes. By LotusScript defintion, only the Integer datatype uses two bytes. The LotusScript Integer is a signed datatype and there's now unsigned 2 bytes datatype in LotusScript. So if you assign this value to a LotusScript Integer variable, the 16th digit is representing the sign bit and the other 15 are representing the real number. The first fifteen bits are set to zero so they represent a zero. Adding the sign bit to that number leads to the lowest possible representable number in a two byte signed integer: -32768.
Well, that was the reason. Now that I kew that I just needed a way to make sure, the value is positive and a long value. At first I was thinking about checking the return value of Val, but then realized this must be way too much work for just converting a value from one number system to another. There must be another way to do that: Finally I found the way to do that: simply add a datatype shortcut to the binary expression and the Val Function gets a directive to convert the value to the appropriate datatype. See the overview of how to accomplis this:
DatatypeLotusScript ShortcutExample
Integer%
Val ( "&b00000000000000001000000000000000" + "%" )
Long&
Val ( "&b00000000000000001000000000000000" + "&" )
Single!
Val ( "&b00000000000000000000000000001000" + "!" )
Double#
Val ( "&b00000000000000001000000000000000" + "#" )


  1. 1) viagra said: (17.03.2017 12:27:45 GMT)
    http://order3onlinev.com/

    Hello!

    { Link } , , { Link } , ,

  2. 2) viagra said: (05.04.2017 16:03:17 GMT)
    generic viagra india pharmacy

    Hello!

    { Link } , , { Link } , ,

  3. 3) viagra said: (06.04.2017 3:19:43 GMT)
    generic viagra india pharmacy

    Hello!

    { Link } , , { Link } , ,

  4. 4) viagra said: (14.04.2017 7:40:57 GMT)
    ipad viagra online sicher

    Hello!

    { Link } , ,

  5. 5) cialis_tadalafil said: (21.04.2017 16:54:38 GMT)
    cialis tadalafil

    Hello!

    { Link } , ,

  6. 6) cheap_viagra said: (23.04.2017 22:44:12 GMT)
    cheap viagra

    Hello!

    { Link } , ,

  7. 7) cheap_cialis said: (25.04.2017 3:55:14 GMT)
    cheap cialis

    Hello!

    { Link } , ,


Add Comment
 
Subject:
   
Name:
E-mail:
Web Site:
 
Comment:  (No HTML - Links will be converted if prefixed http://)
 
Remember Me?