Results 1 to 3 of 3

Thread: Binary !

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Post

    Ummm, ok this is a dumb question maybe, but how do i break down a file into binary. As in 10101010.


    Is it possible to covert characters into binary as in make A = 111000
    whatever

    What about numbers, like 255?

    How about ascii to hex, then binary?

    Any suggestions are appriciated. Thanks
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    To get the binary value just easiset way is to first convert any variable you have into byte or byte array, from strings with Strconv(), one char strings with asc() integers or floating points with copymemory, and opening a file in binary.

    Then to check for each bit in a byte you use and operator:
    Code:
    For Bit = 0 to 7
      debug.?cbool(ByteArr(X) And 2^Bit)
    next Bit
    To convert to Hex use Hex() function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008

    Binary

    Ultimately ALL data is stored as a binary representation. Although you could simply represent each character you want with a stream of binary characters and then write that to a file, this would be pretty inefficient. I remember, long ago, reading an essay on cryptography which represented files with binary numbers only. The key was to set the file to read eight characters at a time, say, and this was then used as a code to tell the program how to interpret the next n characters.

    To represent characters or numbers in binary you need to define a storage area and then use some of that as flags to indicate the data type and other properties. Try looking up Binary Coded Decimal for an example of representations of numbers in binary - the key thing to realise is that the interpretation of a binary stream can be representative of anything you like - you just have to set up the code and decoding mechanisms. At its most basic level that is what an OS does when it translates what we type at a keyboard - a computer does not understand A or B - it merely recieves a stream of binary data.

    Phew.

    Clear as mud, I am sure.

    As to how to break down a file into Binary - hmmm write out ASCII codes as a fixed length Binary Stream - maybe.

    "This255" would be 01010100 01101000 01101001 01110011 00110010 00110101 00110101

    However it gets complicated here because do you interpret the last three codes as 255 (two hundred and fifty five) or 2,5,5?

    See the hot water you are getting into...

    Cheers.

    Paul.
    Not nearly so tired now...

    Haven't been around much so be gentle...

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