Results 1 to 15 of 15

Thread: [VB] boolean

  1. #1

    Thread Starter
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048

    [VB] boolean

    i vaguely remember reading something about how in vb when a boolean variable is used, it is supposed to be 1 byte but actually allocates a lot more space

    anyone even think im not making this up?

    also do all variables end up working this way or what

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Boolean is basically True | False. They may be the only two values which you can read from a boolean variable but in computer terms True and False are defined as the following.

    True: Any non 0 value.
    False: Zero 0

    In actual fact when you declare a boolean data type it uses 16bits (2 bytes). The following code will reveal how the computer stores a boolean value:
    VB Code:
    1. Private Sub Form_Paint()
    2.     Dim bTrue As Boolean, bFalse As Boolean
    3.  
    4.     bTrue = True
    5.     bFalse = False
    6.    
    7.     Print "bTrue = ", CInt(bTrue)
    8.     Print "bFalse = ", CInt(bFalse)
    9. End Sub
    It is also perfectly valid to assign a bollean variable any number: i.e bTrue = 2e45. On doing so the computer will convert the number to the booolean -1 and 0.

    I am not sure why a 16bit variable size is used to store the two values. It may be an issue of optimization. Or for backward compatibility with 16 bit systems.

    Maybe someone else can help out here??
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3
    Hyperactive Member
    Join Date
    Feb 2003
    Location
    Grenada
    Posts
    346
    It may be an issue of optimization. Or for backward compatibility with 16 bit systems.

    Sounds the most logical....
    If my post has been helpful, then please rate it accordingly...
    If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.

  4. #4

    Thread Starter
    Frenzied Member dis1411's Avatar
    Join Date
    Mar 2001
    Posts
    1,048
    so it would technically be more efficient to declare it as a byte

    u can use it exactly as u would a boolean, but its only a byte, so only takes 1 byte of memory

  5. #5
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Originally posted by dis1411
    so it would technically be more efficient to declare it as a byte

    u can use it exactly as u would a boolean, but its only a byte, so only takes 1 byte of memory
    Probably not, becuase a Boolean value is treated differently to a byte. When you declare a Boolean: it means you can assign it any value and it will be converted to True or False. e.g:
    VB Code:
    1. Dim myBln As Boolean
    2.   Dim myByt As Byte
    3.    
    4.   ' valid - value is converted to true
    5.   ' before being assigned to myBln
    6.   myBln = 1345.55
    7.  
    8.   ' invalid - casues an overflow error
    9.   myByt = 1234.55
    10.    
    11.   ' valid - but not as easy as using Boolean
    12.   myBtye = CBool(1234.55)
    It also means that when you do any True | False comparisons such as:
    VB Code:
    1. If myByt Then
    2.     doStuff.....
    3.   End If
    The computer is made to convert the byte value to Boolean type each time. Whereas, if it had already been declared as a Boolean that would only have been done once when the value was assigned.

    The only way declaring it as a byte would make it more efficient is in saving a little memory. If you are that concerned about memory consumption you should move to C++.

    In reality at processor level all numbers are converted to a 32 bit float and shoved through 32 bits at a time - (unless you own a 64bit processor). Simply becuase that is the size of the bus and also becuase it is a lot more efficient for the processor to handle all its calculations using the same data type. So using one byte instead of 2 makes no difference.

    My best advice use Boolean as the data type.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  6. #6
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by visualAd

    In reality at processor level all numbers are converted to a 32 bit float and shoved through 32 bits at a time - (unless you own a 64bit processor). Simply becuase that is the size of the bus and also becuase it is a lot more efficient for the processor to handle all its calculations using the same data type. So using one byte instead of 2 makes no difference.
    That isn't true, it just means it can receive 32bytes at once, not everything is converted to 32byte floats. If that were true, holy **** would computers be slow.

  7. #7
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I think you'll find they do. The processor only handles floating point numbers hence the term FLOP. They also have only one type of logic gate: e.g an AND gate. These are then used to construct other gates such as XOR, NOT, NAND and OR.

    Whats more - it can only add
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    PowerPoster Pc_Madness's Avatar
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    2,765
    Originally posted by visualAd
    Boolean is basically True | False. They may be the only two values which you can read from a boolean variable but in computer terms True and False are defined as the following.

    True: Any non 0 value.
    False: Zero 0

    In actual fact when you declare a boolean data type it uses 16bits (2 bytes). The following code will reveal how the computer stores a boolean value:
    VB Code:
    1. Private Sub Form_Paint()
    2.     Dim bTrue As Boolean, bFalse As Boolean
    3.  
    4.     bTrue = True
    5.     bFalse = False
    6.    
    7.     Print "bTrue = ", CInt(bTrue)
    8.     Print "bFalse = ", CInt(bFalse)
    9. End Sub
    It is also perfectly valid to assign a bollean variable any number: i.e bTrue = 2e45. On doing so the computer will convert the number to the booolean -1 and 0.

    I am not sure why a 16bit variable size is used to store the two values. It may be an issue of optimization. Or for backward compatibility with 16 bit systems.

    Maybe someone else can help out here??
    Possibly because of binary? 8 bits reserved for a zero, and 8 bits reserved for -1/ 1

    Each digit in, "11110000" is a bit yeah?

    Maybe? :unsure:
    Don't Rate my posts.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    Using two's compliment -1 is:

    11111111 11111111 - (represented in 2 bytes)

    and zero is:

    00000000 00000000 - (represented in 2 bytes)

    I'd imagain that is how they store it.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by visualAd
    I think you'll find they do. The processor only handles floating point numbers hence the term FLOP. They also have only one type of logic gate: e.g an AND gate. These are then used to construct other gates such as XOR, NOT, NAND and OR.

    Whats more - it can only add
    After checking out some info, what you said was semi true. Nothing is EVER converted into a 32bit float, however, integers, ect are all put INTO 32bit registers (I think that is the right word)

    So a 16bit integer would be placed into a 32bit register. It isn't converted, the space just doesn't get used (i.e. a bunch of zeros would be added to the front of the binary number)

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    You people ought to read the first few chapters of the DOS version of The Art of Assembly Lanugage Programming. Find the link in the FAQ of the Assembly forum.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    The term FLOPs/s (FLoating point OPerations per second) comes from supercomputing. Supercomputers usually do large simulations where the only interesting calculation is one on floating point numbers.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  13. #13
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    I quote what one of my computing tutors told me.

    He stated that it is cheaper and more effficient for the processor to do one type of calculation on one data type, which will usually be a floating point data type the size of the bus (e.g 32bits).

    I may have miss understood him. I must say this is a very interesting subject though.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Intel's HyperThreading technology relies on the fact that a CPU has various calculation areas (floating point, integers, ...) but is using only one at a time.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    I just recently learned how floating point maths works.

    Addition in floating point is quite complicated, so I suppose it's ages slower than integral addition.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width