Why is True in Visual Basic stored as -1?

It looks like many languages, including C / C ++ and Java, have both Logical Not (which converts 0 to 1 and vice versa) and bitwise (AKA bitwise inversion is one addition). In Visual Basic, it Notis just bitwise and Truehas a value of -1. Is there any special reason why VB was implemented this way?

If some remainder is translated from BASIC, does this mean a change in thinking between 1964 (BASIC) and the time of later languages ​​such as C (1972)?

+4
source share
2 answers

This is just an assumption, but the bit-wise AND / OR / NOT option was probably chosen (in the days of 8-bit BASIC implementations) to simplify the implementation and flexibility compared to zero vs non-zero logic.

You could not make the language too complicated, as it was during the days of the “home computer”, when the processor cycles were in kilohertz, and the memory was in kilobytes, and storage devices where it was rarely or expensive or primitive (for example, a device for recording on paper tape or hastily adapted tape cassette player / player).

Dartmouth BASIC (the beginning of everything, since 1964, http://bitsavers.trailing-edge.com/pdf/dartmouth/BASIC_4th_Edition_Jan68.pdf ), there wasn’t even AND / OR / NOT, not even as keywords for IF.

, BASIC Microsoft, - Altair BASIC (c 1975, https://en.wikipedia.org/wiki/Altair_BASIC). Altair BASIC AND/OR/NOT (https://ia601600.us.archive.org/35/items/bitsavers_mitsMITSAl_6669937/MITS_AltairBASIC_1975.pdf), " " (. 27 - . 31 PDF), Altair BASIC, False/True 0/-1; THEN IF. -, , .

( , , "INTRUDER ALERT" , .)

, AND/OR/NOT , , , / . zero-vs-nonzero , . AND/OR/NOT , parser/ .

NOT 0 -1 ( , 1, ), -1 (, "" ).

, VB.NET ( VB6, ), , Integer. , , VB.NET .

+2

, BASIC AND OR. Not VB.NET, NOT, , .

True -1 , And Or . , , True And 2 - True And CBool(2), , True 1. VB AndAlso OrElse.

+6

Source: https://habr.com/ru/post/1664018/


All Articles