Articles

2.6: Converting Between (our) Base 10 and Any Other Base (and vice versa)


To convert any number in (our base) Base 10 to any other base, we must use basic division with remainders. Do not divide using decimals; the algorithm will not work.

Example (PageIndex{1})

Convert from (our) Base 10 to (weird) Base _____

Change (236_{ ext {ten}}) to ______ (_{ ext {five}})

Solution

Keep dividing by 5, until your quotient is zero.

[egin{aligned}
236 div 5 &=47 ; r ; mathbf{1}
47 div 5 &=9 ; r ; mathbf{2}
9 div 5 &=1 ; r ; mathbf{4}
1 div 5 &=0 ; r ; mathbf{1}
end{aligned} onumber ]

Now write your remainders backwards!

Answer: (1421_{ ext {five}})

Example (PageIndex{2})

Convert from (weird) Base ____ to (our) Base 10.

Solution

First, notice how to break down (602_{ ext {ten}}):

[602_{ ext {ten }}: 602=6left(10^{2} ight)+0left(10^{1} ight)+2left(10^{0} ight) onumber ]

Now, use the same approach to change (602_{ ext {eight}}) into Base 10

[6left(8^{2} ight)+0left(8^{1} ight)+2left(8^{0} ight)=386_{ ext {ten}} onumber ]

Example (PageIndex{3})

Convert (5361_{ ext {seven}}) into Base 10.

Solution

[5left(7^{3} ight)+3left(7^{2} ight)+6left(7^{1} ight)+1left(7^{0} ight)=1905_{ ext {ten }} onumber ]

Partner Activity 1

  1. Convert the base 10 numbers into base 4
    1. (30_{ ext {ten}}) = _____ (_{ ext {four}})
    2. (2103_{ ext {ten}}) = _____ (_{ ext {four}})
    3. (16_{ ext {ten}}) = _____ (_{ ext {four}})
  2. Convert the base 5 numbers into base 10
    1. (30_{ ext {five}}) = ______ (_{ ext {ten}})
    2. (2103_{ ext {five}}) = ______(_{ ext {ten}})
    3. (16_{ ext {five}}) = ______ (_{ ext {ten}})

Think carefully about 2c!

***For extra practice, click here.

Practice Problems

  1. Write the following Base 10 numbers into the new Base.
    1. 5567 into Base 9
    2. 12 into Base 4
    3. 100 into Base 3
    4. 73 into Base 2
  2. Write the following numbers into Base 10.
    1. (64_{ ext {seven}})
    2. (157_{ ext {eight}})
    3. (1001001_{ ext {two}})
    4. (84671_{ ext {eleven}})

2.6: Converting Between (our) Base 10 and Any Other Base (and vice versa)

Can you convert the following number to binary ?

This is good but has one fatal flaw.

This causes an error due to the attempt to support negative signs on the final string. The problem is that the MinValue for Int has no corresponding positive value so doing this:

doesn't actually change the sign. To get around this one would have to use uint and determine if the number should be negative or not. Like so:

Working with this more, I've added a means by which to get either the signed or unsigned equivalent of the number sent in.

Using HEX for example the integer value -2147483647 would come out as -7FFFFFFF if you wanted the negative sign appended (like the above method does). But what if you didn't want the signed version and wanted how it would actually be represented in the system or (if not using HEX how it'd be if not signed). It should be 80000001 (hex).

Here's the modified code to do both:

This was very helpful to me.
Thank you very much.

I have made a few changes including:

Support for negative numbers,

adding a zeroPadding parameter - set to 1 to get "0", 0 to get "" as before and 4 to get "0001" etc.

Improvement to the speed - to do all numbers 0 to 1 million in hex was taking 33 seconds, with this new version it takes 0.8 seconds.

Hope someone finds it usefull

I think you have a typo error at "if (int i=maxi ".

Appologies for loosing a bit

But it looks like you have fixed it now anyway

Anyway, I debugged it and below is the result. I just had to renamed all the variables to follow my coding standard. Thanks to you and to Balamurali, because I used this routine in my project.


private string DecimalToBase(int decimal_number, int number_base, int zero_padding)
<
if (number_base > 16 || number_base < 2)
<
throw new System.ArgumentOutOfRangeException (
"number_base", number_base, "number_base - Range: 2..16")
>

if (zero_padding < 0)
<
throw new System.ArgumentOutOfRangeException (
"zero_padding", zero_padding, "zero_padding should be positive")
>

System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder()

if (decimal_number < 0)
<
isNegative = true

decimal_number *=-1
>
else
<
isNegative = false
>

int[] remainders = new int[MAX_BIT]

for( decimal_number > 0 decimal_number /= number_base)
<
remainders[--max] = decimal_number % number_base
>

if (decimal_number > 0)
<
throw new System.ArgumentOutOfRangeException (
"decimal_number", decimal_number, "decimal_number - Too large")
>

for (int i = max i < MAX_BIT i++)
<
stringBuilder.Append(hexCharacters[remainders[i]])
>

string s = stringBuilder.ToString()

int zero_padding_required = zero_padding - (MAX_BIT - max)

if (zero_padding_required > 0)
<
stringBuilder.Insert(0, new string('0', zero_padding_required))
>

if (isNegative)
<
stringBuilder.Insert(0, '-')
>

General News Suggestion Question Bug Answer Joke Praise Rant Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Python 3.0¶

The development cycle for Python versions 2.6 and 3.0 was synchronized, with the alpha and beta releases for both versions being made on the same days. The development of 3.0 has influenced many features in 2.6.

Python 3.0 is a far-ranging redesign of Python that breaks compatibility with the 2.x series. This means that existing Python code will need some conversion in order to run on Python 3.0. However, not all the changes in 3.0 necessarily break compatibility. In cases where new features won’t cause existing code to break, they’ve been backported to 2.6 and are described in this document in the appropriate place. Some of the 3.0-derived features are:

A __complex__() method for converting objects to a complex number.

Alternate syntax for catching exceptions: except TypeError as exc .

The addition of functools.reduce() as a synonym for the built-in reduce() function.

Python 3.0 adds several new built-in functions and changes the semantics of some existing builtins. Functions that are new in 3.0 such as bin() have simply been added to Python 2.6, but existing builtins haven’t been changed instead, the future_builtins module has versions with the new 3.0 semantics. Code written to be compatible with 3.0 can do from future_builtins import hex, map as necessary.

A new command-line switch, -3 , enables warnings about features that will be removed in Python 3.0. You can run code with this switch to see how much work will be necessary to port code to 3.0. The value of this switch is available to Python code as the boolean variable sys.py3kwarning , and to C extension code as Py_Py3kWarningFlag .

The 3xxx series of PEPs, which contains proposals for Python 3.0. PEP 3000 describes the development process for Python 3.0. Start with PEP 3100 that describes the general goals for Python 3.0, and then explore the higher-numbered PEPS that propose specific features.


Address to Lat Long

Address to Lat Long has the option convert address to lat long.

Type in the address field above and click on the Get GPS Coordinates button.

The Geocoded address will show up on the map coordinates along with the address.

Latitude and Longitude will be shown in both the DMS format (degrees, minutes, seconds) and DD format (decimal degrees).

If you are not sure where you are currently at, you can use our longitude and latitude tool to find your current address and gps coordinates, and then use the gps coordinates converter tool to convert your current location.

How to use the coordinates converter?

There are two ways that you can use the coordinates converter to convert a coordinates to an actual address.

Coordinate Converter to Decimal converts latitude and longitude to decimal degrees and vice versa, coordinate converter to address and it is also able to convert decimal to degree minute second.

Degrees Minutes Seconds to Decimal Degrees

The degrees minutes seconds to decimal degrees or DMS Converter is a tool to convert any address or coordinates to decimal degrees format and convert decimal degrees to the degrees minutes seconds format.


What Is a Hexadecimal?

A hexadecimal, which is also called base 16 or "hex" for short, is a representation of four binary bits and consists of sixteen numbers and letters. The numbers in a hex are the same as decimal numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. The big difference between a hex and a decimal is that a hex also contains letters. These letters are: A, B, C, D, E, F.

A hex number can be represented using a subscript of 16 (i.e. 23516). These letters come after the decimals in ascending order. Therefore, the hexadecimal series looks like this: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F. A hex can be considered a shorter version of a decimal. For example a large number in decimal form has a much smaller hex equivalent (using less hex bits to represent the decimal number). I will demonstrate this later.


Octal

Finally, the same holds for octal. Any guesses on how many digits are in the octal number system? Octal stands for eight. Right, octal contains eight digits. And instead of bin() or hex(), we use oct() to convert numbers to octal in Python. We prefix octal numbers with a zero followed by a lowercase o, like ‘0o’.

The eight digits of octal are 0, 1, 2, 3, 4, 5, 6, 7.

Let’s use the same code sample here, but we’ll use the proper notation and conversion function for octal.


Converting Between Mixed and Improper Fractions (A)

Teacher s can use math worksheets as test s, practice assignment s or teaching tool s (for example in group work , for scaffolding or in a learning center ). Parent s can work with their children to give them extra practice , to help them learn a new math skill or to keep their skills fresh over school breaks . Student s can use math worksheets to master a math skill through practice, in a study group or for peer tutoring .

Use the buttons below to print, open, or download the PDF version of the Converting Between Mixed and Improper Fractions (A) math worksheet. The size of the PDF file is 26751 bytes . Preview images of the first and second (if there is one) pages are shown. If there are more versions of this worksheet, the other versions will be available below the preview images. For more like this, use the search bar to look for some or all of these keywords: math, fractions, converting, mixed, improper .

The Print button will initiate your browser's print dialog. The Open button will open the complete PDF file in a new tab of your browser. The Teacher button will initiate a download of the complete PDF file including the questions and answers (if there are any). If a Student button is present, it will initiate a download of only the question page(s). Additional options might be available by right-clicking on a button (or holding a tap on a touch screen). I don't see buttons!

The Converting Between Mixed and Improper Fractions (A) Math Worksheet Page 1 The Converting Between Mixed and Improper Fractions (A) Math Worksheet Page 2

Python Program to Convert Decimal to Binary, Octal and Hexadecimal

In this program, you'll learn to convert decimal to binary, octal and hexadecimal, and display it.

To understand this example, you should have the knowledge of the following Python programming topics:

The decimal system is the most widely used number system. However, computers only understand binary. Binary, octal and hexadecimal number systems are closely related, and we may require to convert decimal into these systems.

The decimal system is base 10 (ten symbols, 0-9, are used to represent a number) and similarly, binary is base 2, octal is base 8 and hexadecimal is base 16.

A number with the prefix 0b is considered binary, 0o is considered octal and 0x as hexadecimal. For example:


Mass-to-Mole Conversions

Mass-to-mole conversions can be facilitated by employing the molar mass as a conversion ratio.

Learning Objectives

Convert from grams to moles using a compound’s molar mass.

Key Takeaways

Key Points

  • The mole is the universal measurement of quantity in chemistry. Although it is not possible to directly measure how many moles a substance contains, it is possible to first measure its mass and then convert that amount to moles.
  • A substance’s molar mass is calculated by multiplying its relative atomic mass by the molar mass constant (1 g/mol).
  • The molar mass constant can be used to convert mass to moles. By multiplying a given mass by the molar mass, the amount of moles of the substance can be calculated.

Key Terms

  • molar mass: The mass of a given substance (chemical element or chemical compound) divided by its amount (mol) of substance.
  • mole: In the International System of Units, the base unit of the amount of substance the amount of substance of a system that contains as many elementary entities as there are atoms in 12 g of carbon-12.

The mole is the universal measurement of quantity in chemistry. However, the measurements that researchers take every day provide answers not in moles but in more physically concrete units, such as grams or milliliters. Therefore, scientists need some way of comparing what can be physically measured to the amount of measurement they are interested in: moles.

Molar Mass

Because scientists of the early 18th and 19th centuries could not determine the exact masses of the elements due to technology limitations, they instead assigned relative weights to each element. The relative atomic mass is a ratio between the average mass of an element and 1/12 of the mass of an atom of carbon-12. From this scale, hydrogen has an atomic weight of 1.0079 amu, and sodium has an atomic weight of 22.9997 amu.

From the relative atomic mass of each element, it is possible to determine each element’s molar mass by multiplying the molar mass constant (1 g/mol) by the atomic weight of that particular element. Multiplying by the molar mass constant ensures that the calculation is dimensionally correct because atomic weights are dimensionless. The molar mass value can be used as a conversion factor to facilitate mass-to-mole and mole-to-mass conversions.

Converting Grams to Moles

The compound ‘s molar mass is necessary when converting from grams to moles.

  • For a single element, the molar mass is equivalent to its atomic weight multiplied by the molar mass constant (1 g/mol).
  • For a compound, the molar mass is the sum of the atomic weights of each element in the compound multiplied by the molar mass constant.

After the molar mass is determined, dimensional analysis can be used to convert from grams to moles.

Mass and mole conversions: The mass and molar quantities of a substance can be easily interconverted by using the molecular weight as a conversion factor.

Example 1

For example, convert 18 grams of water to moles of water. The molar mass of water is 18 g/mol. Therefore:

Example 2

If you have 34.5 g of NaCl, how many moles of NaCl do you have?

Stoichiometry, Grams to Moles – YouTube: This video describes how to determine the number of moles of reactants and products if given the number of grams of one of the substances in the chemical equation.


Examples: Vice Versa in Sentences

This device features 1080p up-conversion and 2-way dubbing. This way, you are able to transfer from VHS tapes to DVDs and vice versa. —Fox News

“It wouldn’t exactly be the first time racial ideas have come from the US or vice versa,” he said. —ABC

Effectively, U.S. armed forces can operate out of Indian bases, and vice versa, on a simple basis. —Forbes

“There are times when I’m really happy and I write something really sad, and vice versa.” —The Guardian


Watch the video: Conversions and Rates (December 2021).