home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / LordLucifer / win32asm / tutorials / a_tut1.txt < prev    next >
Encoding:
Text File  |  2000-05-25  |  4.5 KB  |  118 lines

  1. Binary Numbers and Logic
  2.  
  3. By Lord Lucifer
  4. April 21, 1998
  5.  
  6.  
  7. Introduction
  8. -----------------------------------------------------------------------------
  9.  
  10. Having a basic understanding of how a computer works is essential to
  11. successfull programming.  Merely jumping in blindly and trying
  12. to hack some code together is not even a remotely good practice.
  13. Lacking the basic knowledge leads to bugged and bloated programs, not to
  14. mention long hours of coding, testing and debugging.  Wouldn't it be
  15. nice if everyone took the time to properly write a fast and efficient
  16. program, instead of rushing it out the door??
  17.  
  18. This lesson teaches the very basics of computers, binary numbers and
  19. boolean logic.  These are simple concepts, and if you do not already
  20. understand them, you would be well advised to do so...
  21.  
  22. Note:
  23.   This tutorial may actually lessen your knowledge of these topics...
  24.   This is not my intent, but could be the result nevertheless...
  25.   For a much more in-depth (and better) discussion, go to:
  26.   Binary Numbers:
  27.    http://webster.ucr.edu/Page_asm/ArtofAssembly/CH01/CH01-1.html#HEADING1-34
  28.   Boolean Logic:
  29.    http://webster.ucr.edu/Page_asm/ArtofAssembly/CH02/CH02-1.html#HEADING1-3
  30.  
  31.  
  32. Binary Numbers
  33. -----------------------------------------------------------------------------
  34.  
  35. Decimal Numbers:
  36.   In order to understand binary numbers, we must first refresh our knowledge
  37.   of the decimal number system.  If you do not already know this information,
  38.   assembly programming is probably not for you....instead, go and play some
  39.   video games, they're very entertaining.  Anyways...
  40.  
  41.   The decimal number system is base-10, meaning its digits are based upon
  42.   powers of 10.  It also means that each digit can represent one of 10
  43.   different values (0-9). For example, the number 443556 can represented as:
  44.  
  45.   443556 = 4x10^5 + 4x10^4 + 3x10^3 + 5x10^2 + 5x10^1 + 6x10^0
  46.          = 400,000 + 40,000 + 3,000 + 500 + 50 + 6
  47.  
  48. Binary Numbers:
  49.   The binary number system is base-2; its digits are based upon powers
  50.   of 2.  Each digit can represent one of 2 different values (0,1).
  51.   
  52.   To convert binary to decimal is simple:
  53.   0100 1010b = 0x2^7 + 1x2^6 + 0x2^5 + 0x2^4 + 1x2^3 + 0x2^2 + 1x2^1 + 0x2^0
  54.              = 64 + 8 + 2 = 74d
  55.  
  56.   Converting decimal to binary is slightly more complex:
  57.   You'll need to work backwards, finding the greatest power of 2 which is
  58.   less than the number you wish to convert.  Then continue for each lesser
  59.   power of 2 until 2^0.
  60.  
  61.   For Example, convert 1998 to binary:
  62.  
  63.     1x2^10 = 1024      1998-1024 = 974
  64.     1x2^9  = 512       974-512 = 462
  65.     1x2^8  = 256       462-256 = 206
  66.     1x2^7  = 128       206-128 = 78
  67.     1x2^6  = 64        78-64 = 14
  68.     ...
  69.     1x2^3  = 8         14-8 = 6
  70.     1x2^2  = 4         6-4 = 2
  71.     1x2^1  = 2         2-2 = 0
  72.  
  73.     1998d = 0111 1100 1110b
  74.  
  75.   In a computer, all data is stored in binary form.  Each binary digit in a
  76.   computers is known as a bit. A byte is equal to 8 bits, while a word is
  77.   16 bits, and a dword is 32 bits.
  78.   
  79. Hexadecimal Numbers:
  80.   Hexadecimal (Hex) numbers are base-16. They are a concise way of
  81.   representing binary numbers.  It represents each byte of data as a base-16
  82.   number.  Because there are only 10 numerals, the letters A-F are used for
  83.   the remaining 6 digits. Following is a table of binary numbers and their
  84.   hexadecimal equivalents:
  85.  
  86.   Bin   Hex    Bin   Hex    Bin   Hex    Bin   Hex
  87.   0000  0      0100  4      1000  8      1100  C
  88.   0001  1      0101  5      1001  9      1101  D
  89.   0010  2      0110  6      1010  A      1110  E
  90.   0011  3      0111  7      1011  B      1111  F
  91.  
  92.   Therefore: 0010 1001 1010b = 29Ah
  93.  
  94.   As you can see, 29A is much easier to read and write than it is in binary
  95.   form.  Plus, the conversion is trivial, so it makes sense to use hex
  96.   numbers when dealing with computers...
  97.                                    
  98.  
  99. Boolean Logic
  100. -----------------------------------------------------------------------------
  101.  
  102. Everyone should remeber logic from math class.. If not heres a brief
  103. introduction to it.  Boolean logic is a math system closed over the values
  104. 0 and 1. I will not give a complete discussion of boolean logic, just
  105. a few minor points that may be useful for programming.
  106.  
  107.   AND            OR             XOR            NOT
  108.   X  Y   Z       X  Y   Z       X  Y   Z       X  Z
  109.   0  0   0       0  0   0       0  0   0       0  1
  110.   0  1   0       0  1   1       0  1   1       1  0
  111.   1  0   0       1  0   1       1  0   1
  112.   1  1   1       1  1   1       1  1   0
  113.  
  114.  
  115. -----------------------------------------------------------------------------
  116. Copyright (C) 1998
  117. Lord Lucifer (lord-lucifer@usa.net)
  118.