Thread: binary problem

  1. #16
    Frustrated Programmer :( phantom's Avatar
    Join Date
    Sep 2001
    Posts
    163
    thanks...

  2. #17
    Unregistered
    Guest
    Originally posted by no-one

    >Also, what are the types of number maths that C++ is based on?
    octal? hexadecimal? binary...<

    I would say decimal, all the math in computers is done at the lowest level in binary but it can easily be made to represent decimal math which is usually the case, so knowing binary math is not neccessary to use the math facilities of C++ or virtually any language for that matter.
    Well, this isn't *quite* true.

    Integer math is integer math, and it's all the same in any base. So is floating point math IF we had infinite precision. But, this is not the case.

    So, computers really DO use binary math, as some numbers which can be represented with a finite precision number in decimal (like 0.3) cannot be represented in a finite number of bits in binary, so your float can never contain *exactly* 0.3.

    For 99.9% of users and applications, who really cares? You can think of it as decimal math. But, when you need *true* decimal math, math which is actually done at every stage in decimal, you need to use different means (like binary coded decimal) to do TRUE decimal math.

    I agree, though, for all intents and purposes, most people never care how the math is being done internally.

  3. #18
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    and if anyone has any unanswered questions or is still confused feel free to ask.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  4. #19
    Registered User UneducatedOne's Avatar
    Join Date
    Sep 2001
    Posts
    57
    So octal and hexadecimal are not used at all?
    not even for graphics?
    Is graphics all trigonometry?
    ~Thank you~

    some have it, some don't, watch out for those who do....

  5. #20
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >So octal and hexadecimal are not used at all?

    octal is not used a lot AFAIK,
    but hex is used quite frequently for assembler graphics, and is typically used for defines and interupts and the like, but if you mean for math functions its all eventually broken down to binary then multplied or whatever.

    hex,dec,and octal can be used intercangably when useing integer math.

    >Is graphics all trigonometry?

    it depends on the type of graphics some require Calculus some just Trig, Geometry, and Algebra, most 3D Graphics require a mix of Trig, Geo, and Algebra 1 / 2 with a splash of Calculus(rarely), but again some graphics require Extreme Knowlege of Calculus.

    what math you need all depends on what type of Graphics and how much you really want to do.

    some say you need it some say you don't.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  6. #21
    Registered User UneducatedOne's Avatar
    Join Date
    Sep 2001
    Posts
    57
    Is graphics programming sort of seen as " the highest level achievable " by a programmer?, if not, what is?
    ~Thank you~

    some have it, some don't, watch out for those who do....

  7. #22
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    >Is graphics programming sort of seen as " the highest level achievable " by a programmer?, if not, what is?<

    well this really depends on the programmer and what he wants to do, though there is no real " highest level achievable " theres always room to learn more.

    but in an attempt to answer your question i don't think graphics is seen as the highest level by most, more likey that highly advanced mathmatical algorithims and the like are of a higher level, such as those needed in cryptography.

  8. #23
    Unregistered
    Guest
    >>Also, what are the types of number maths that C++ is based >>on?
    >>octal? hexadecimal? binary...

    >>I would say decimal, all the math in computers is done at the >>lowest level in binary but it can easily be made to represent >>decimal math which is usually the case, so knowing binary >>math is
    >>not neccessary to use the math facilities of C++ or virtually any >>language for that matter.

    Why do you think so? How many bits do you need to store a single digit decimal number? Four of course, but nine is 1001, so values over 1001 are "unused." In case of hexadecimal, you use four bits too, but you use them in all variations, from 0000 to 1111 for F, is that right? Computers would use hexa numbers if people would think hexadecimally (some programmers do, but normal people does not). Isn't it the only reason to use decimal numbers on computers? So much easier should be (for computer) to view numbers in hexa, not decimal.

  9. #24
    larry
    Guest
    >>Also, what are the types of number maths that C++ is based >>on?
    >>octal? hexadecimal? binary...

    >>I would say decimal, all the math in computers is done at the >>lowest level in binary but it can easily be made to represent >>decimal math which is usually the case, so knowing binary >>math is
    >>not neccessary to use the math facilities of C++ or virtually any >>language for that matter.

    Why do you think so? How many bits do you need to store a single digit decimal number? Four of course, but nine is 1001, so values over 1001 are "unused." In case of hexadecimal, you use four bits too, but you use them in all variations, from 0000 to 1111 for F, is that right? Computers would use hexa numbers if people would think hexadecimally (some programmers do, but normal people does not). Isn't it the only reason to use decimal numbers on computers? So much easier should be (for computer) to view numbers in hexa, not decimal.

  10. #25
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    How are values over 1001 unused? 1010 = 10, 1011 = 11, 1100 = 12, etc...

    Am I missing something?

  11. #26
    Registered User larry's Avatar
    Join Date
    Sep 2001
    Posts
    96
    I mean one digit. One decimal digit needs 4 bits, but not all values and one hexadecimal digit needs 4 bits and uses all values. I don't use binary numbers a lot, so I don't understand them well, but I think it's much simpler to "slice" number like 100101111001 into three 4bit pieces and decode them to 9, 7 and 9 - you get the result > 0x979. Decoding this number into a decimal (2425 or something) is much more complex. Don't think of this as something to discuss, it's just a remark.

    Oh, and one more thing: In my opinion, the best explanation of decimal values of single bits is through number two. Not values 1, 2, 4, 8,etc but 2^0, 2^1, 2^2, etc. It's easier to understand and easier to write an algorhitm.

  12. #27
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    Yeah, but AFAIK, numbers stored in binary form aren't stored in their decimal digit equivalent... It wouldn't make any sense...

  13. #28
    Registered User
    Join Date
    Sep 2001
    Posts
    412
    Numbers ARE stored in binary in a computer, *almost* always. All the math done is binary math.

    Buuuut, MATH is MATH. For integer math, it doesn't matter HOW the numbers are stored -- you could use base 43 and all laws of math would be equally valid, and you could convert your answer to any base.

    The *only* reason it matters at ALL is for cases where you need to exactly represent decimal fractions. Calculator programs, spreadsheet programs, etc. often DO use floating point math in BCD (binary coded decimal).

    As I recall, there are a few kinds of BCD, and yes, each digit is 4 bits, with 6 "wasted" possibilities. I think, actually, they skip the first and last 3 combos, so "zero" is coded as 0011, and "nine" is 1100. There's some reason why this makes mathematics easier, but I forgot why.

    But, for 99.9% of programs, all ints, floats, and the like are stored as binary values, and all math is binary math. But, the PROGRAMMER never needs to know more than rudimentary math. It helps, for example, to understand binary for bitshifting, bitmasking, etc. but it's hardly required to write most programs.

    So, you may consider all math to be "decimal" because it's a handy way to think. In C/C++, you can use literals in decimal, hexadecimal, or octal, as you prefer. It's all the same -- the compiler converts them all to binary anyway.

    So, unless the fact that your long double will never be able to store *exactly* 0.3 is a huge issue to you, you will never need BCD, you will never need to care that your math is done in binary not decimal. Because, it's really exactly the same.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. problem in binary search
    By LINUX in forum C++ Programming
    Replies: 1
    Last Post: 01-28-2009, 08:50 AM
  2. Problem with Binary File I/O
    By DirX in forum C++ Programming
    Replies: 4
    Last Post: 03-01-2004, 09:34 AM
  3. Binary trees search problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 02-22-2004, 02:29 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. binary tree problem - help needed
    By sanju in forum C Programming
    Replies: 4
    Last Post: 10-16-2002, 05:18 AM