Shop OBEX P1 Docs P2 Docs Learn Events
Numbering systems ? — Parallax Forums

Numbering systems ?

bennettdanbennettdan Posts: 614
edited 2006-06-25 00:57 in General Discussion
Hello,
··· Does anyone have a an idea where I can find info on numbering systems and how to convert· Octal to Decimal to Hex·to Binary and so forth?

Post Edited (bennettdan) : 6/22/2006 1:56:41 AM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-21 22:10
    Any basic computer science textbook will have plenty of information about number systems and about converting back and forth. Keep in mind that Octal, Decimal, and Hex are strictly for external representations. Internally, essentially all modern day computers, including microcontrollers, use multiples of 8 bits to represent everything. 8 bits will hold a number from zero to 255 or from -128 to +127 or any other set of 256 values like a character set. Similarly, a 16 bit quantity can represent 65,536 discrete values like numbers from -32768 to +32767. A computer like the Stamp can convert an 8 or 16 bit value into or from its decimal or hexadecimal representation as a sequence of characters. In the case of a Stamp, this is built-in to the various input/output statements like SEROUT or DEBUG. For other computers like the Propellor or Pentium, there are subroutines provided in "libraries" or built-in to the compilers and their run-time systems that do this for you.
  • bennettdanbennettdan Posts: 614
    edited 2006-06-21 22:18
    Thanks
    Any links to the info on the web?
  • BongoBongo Posts: 65
    edited 2006-06-21 23:47
    Use the calculator on your PC in scientific view



    bongo
  • SSteveSSteve Posts: 808
    edited 2006-06-22 00:00
    You just multiply each digit in the number by the base to the power of the digit's position. It's easier with an example. Say you have the number '5432'.

    In hex, it's (5 * 16^3) + (4 * 16^2) + (3 * 16^1) + (2 * 16^0) = 21554
    In decimal, it's (5 * 10^3) + (4 * 10^2) + (3 * 10^1) + (2 * 10^0) = 5432
    In octal, it's (5 * 8^3) + (4 * 8^2) + (3 * 8^1) + (2 * 8^0) = 2842

    "16^3" means 16 to the third power
    Any number to the zero power equals 1, so (x * y^0) = x

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • SSteveSSteve Posts: 808
    edited 2006-06-22 00:13
    Oh, yeah, the other direction. Converting hex or octal to binary is easy. Each hex digit is four binary digits and each octal digit is three binary digits. Just go through the number and convert each digit to its binary equivalent and string them together:

    5432 (hex) = 0101_0100_0011_0010 = 0101010000110010
    5432 (octal) = 101_100_011_010 = 101100011010

    To convert decimal to hex, you have to divide the number by each power of 16 (ignoring the remainder), then subtract the value of that hex digit and continue. Luckily, division in PBASIC ignores the remainder automatically.

    21554 (decimal):

    21554 / (16^3) = 5
    21554 - (5 * 16^3) = 1074
    1074 / (16^2) = 4
    1074 - (4 * 16^2) = 50
    50 / (16^1) = 3
    50 - (3 * 16^1) = 2

    So 21554 decimal = 5432 hex

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    OS-X: because making Unix user-friendly was easier than debugging Windows

    links:
    My band's website
    Our album on the iTunes Music Store
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 01:55
    What about the letters in Hex? 10=A, 11=B and so own how high do they go? does 1515 mean ff?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-22 02:50
    Yes. The convention is that "digits" above 9 are written using the alphabet beginning with "A".
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 03:45
    so does the # 1515 = ff in Hex?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-06-22 04:14
    That depends on what you mean by 1515. If you mean the 8 bit value represented by 8 one bits then yes, this is usually written as "$ff" or "0xff" depending on the conventions of the system you're using. "0xff" is how hexadecimal values are written in C. Most assemblers and some compilers (like Stamp Basic) use the convention of "$ff" and usually upper and lower case letters are equivalent. Some systems use "%11" for binary numbers so "%11110101" is equivalent to "$f5" or "245" and "%0110101000011100" is the same as "$6a1c".
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-06-22 15:57
    It is all very confusing unless you understand the purposes involved.
    Try to understand what you need a certain format for.
    I am not going to discuss 'floating point' as it is an advanced topic, more abstracted from the machine, and I am not good at it.

    Binary is what the microprocessor uses and sees [noparse][[/noparse]But it is often hard to read when counting. It is good for showing exactly which port is high or low]

    Hexadecimal is easier to read and easier to identify as not being decimal [noparse][[/noparse]because it has A,B,C....] It generally is used for counting and calculation of addresses in microprocessor.

    Octal was used early on, but most people got it confused with decimal and now avoid it.

    Binary Coded Decimal allows you to send, receive, and store two digits in ONE byte, but only numbers. IT is really prefered for clocks and calendars as months, days, years, hours, minutes, and second can all be stored as one byte each.

    ASCII only allows one digit per byte, but you can mix it with the alphabet for text and some control characters.

    Two's Compliment [noparse][[/noparse]made by taking one's compliment and adding a one] allows the microprocessor to have positive and negative digits that are easily manipulated. There are other systems of positive and negative besides this, but they are mostly history [noparse]/noparse]see [u]The Art of Electronics[/u.

    Thusly, one begins to see four purposes. A. Ease of allowing the programmer to read B. Ease of compactly storing digits in some cases C. Clearly showing exactly what the bits are doing. D. some special display conversions

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan

    Post Edited (Kramer) : 6/22/2006 4:01:25 PM GMT
  • aalegadoaalegado Posts: 66
    edited 2006-06-22 16:45
    I know what you're trying to represent with the number "1515" but since that's a decimal number, it would have to be read 1,515 (one thousand, five hundred fifteen) since there no way to "punctuate" those characters to indicate that the left-hand 15 corresponds to the most-significant digit in "FF" and the right-hand 15 corresponds to the least-significant digit in "FF".

    255 dec = FF hex because 15 * 16^1 + 15 * 16^0 = 240 + 15 = 255.

    You can generalize the rule about working in different bases by remembering that in decimal, the right-most (least significant digit) has the weight of 1, the second digit from the decimal point has the weight 10, and so. As you go from right to left, the power of 10 increases. We're taught this in school so even though we aren't conscious of it, if we read the decimal number "123" we "know" that it has that value because we're doing this in our head:

    123 = (10^2 x 1) + (10^1 x 2) + (10^0 x 3)

    or

    123 = 100 + 20 + 3

    The same thing works for any base. Replace the 10's with 16's and you can see that the least-significant digit has the weight of 1 (every LSD is this way because the weight is always the base to the 0th power which is defined as 1), the next most significant digit has the weight 16, the next 256, and so on.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    I wouldn't connect that if I were you...
  • bennettdanbennettdan Posts: 614
    edited 2006-06-22 17:03
    Thanks for you help I understand BCD and binary well because I program PLC's but have not worked with Hex much the letters confuse me a little. Thanks for you help guys I should be able to sort it out now. I am going to make me a chart for quick reference.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2006-06-23 08:37
    I think part of the confusion is that the industry is divided into two groups that don't want to give up their own system of notational clues.

    For instance, Parallax uses one system and Microchip uses the other. I tend to know only Parallax's set up as I do most of my reading in their material. If you are only using 8bit, it is easier to guess, but now that 32bit is being used I sometimes find myself faltering.

    This even goes into how the 'image files' are formated to download HEX data into an EEPROM. There again are two different formats that are historically divided along the loyalties to two major manufactures.

    To really be versitle, you must go the extra distance and remember both sets of information. This is just the way the world works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    "If you want more fiber, eat the package.· Not enough?· Eat the manual."········
    ···················· Tropical regards,····· G. Herzog [noparse][[/noparse]·黃鶴 ]·in Taiwan
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-23 14:35
    One thing to consider is that most PCs have Windows on them.· In Windows there is a claculator which has a Scientific View.· In that mode you can type in a number and convert between DEC, BIN, HEX, OCT with just a click.· It's an easy way to convert and make comparisons.· I use it myself sometimes when I see a long HEX number and want to convert it to decimal or binary. or visa-versa.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 18:03
    Thanks Chris for the tip.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-06-23 18:11
    This is one of those cases where I just like to point out extra tools which can help people.· I have been doing this stuff for 25+ years and I still need to use a calculator or conversion utility once in awhile.· Another great tool is a program called, "CONVERT.EXE" which is free.· I even added the ability to convert bewteen uF, nF and pF since all the decimal places make my head spin.· =)

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • bennettdanbennettdan Posts: 614
    edited 2006-06-23 18:17
    Yeah I know what you mean. I am a electrical/PLC guy that is getting into electronics and love it. Thanks for you help again!
  • BongoBongo Posts: 65
    edited 2006-06-25 00:46
    Is this text invisable?

    bongo
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-06-25 00:57
    Yes.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    When you get 1st Place in the "Darwin Awards", you're a Winner & a Loser.
Sign In or Register to comment.