People also ask

How to convert hexadecimal BC to decimal?
To convert hexadecimal BC to decimal, multiply each digit by the corresponding power of 16 (from right to left) and sum the results. Hexadecimal BC = decimal 188.
๐ŸŒ
calculat.io
calculat.io โ€บ ๐Ÿช„ home โ€บ ๐Ÿ”ข number calculators โ€บ ๐Ÿ”ข hex to decimal โ€บ ๐Ÿ”ข bc in decimal
BC in decimal - Calculatio
How do I convert Hex to Decimal?
To convert from hex (base 16) to decimal (base 10), multiply each digit by 16 raised to its position power and sum.
๐ŸŒ
coolconversion.com
coolconversion.com โ€บ home โ€บ math & numbers โ€บ number base converter
BC Hex = 188 Decimal | Conversion with Steps
Why would I need to convert hex to decimal?
Number base conversions are used in programming, computer science, and digital electronics.
๐ŸŒ
coolconversion.com
coolconversion.com โ€บ home โ€บ math & numbers โ€บ number base converter
BC Hex = 188 Decimal | Conversion with Steps
๐ŸŒ
CoolConversion
coolconversion.com โ€บ math โ€บ binary-octal-hexa-decimal โ€บ _hexadecimal__BC_to_decimal_+โ€”+Hexadecimal+to+Decimal+Calculator+
Convert hexadecimal number BC to decimal | Hexadecimal to Decimal Calculator
Convert from/to decimal, hexadecimal, octal, and binary. Hexadecimal Base Conversion Calculator. Here you can find the answer to questions like Convert hexadecimal number BC to decimal Hexadecimal to Decimal Calculator or Hexadecimal to decimal conversion.
๐ŸŒ
Binary Hex Decimal Converter
binaryhexconverter.com โ€บ hex-to-decimal-converter
Hexadecimal to Decimal Converter
The hexadecimal system (shortly hex), uses the number 16 as its base (radix). As a base-16 numeral system, it uses 16 symbols. These are the 10 decimal digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) and the first six letters of the English alphabet (A, B, C, D, E, F).
๐ŸŒ
GetCalc
getcalc.com โ€บ home โ€บ digital numbers โ€บ hex calculator โ€บ (bc)16 in decimal
BC Hex to Decimal: (BC)16 = (?)10
The decimal equivalent of left most number B in hex BC should be multiplied with 16(no. of digits in hex - 1). For hex values other than BC, use this below tool:
๐ŸŒ
nixCraft
cyberciti.biz โ€บ nixcraft โ€บ howto โ€บ bash shell โ€บ linux / unix: convert hexadecimal to decimal number
Linux / UNIX: Convert Hexadecimal to Decimal Number - nixCraft
November 23, 2010 - But you neednโ€™t fuss over converting the decimal โ€œ10โ€ to binary โ€œ1010โ€ just to let bc interpret obase correctly โ€“ just specify the โ€œobase=10โ€ before specifying the ibase: ... Your perl-example is a โ€œ,โ€ after the format-part missing: # perl -e โ€˜printf โ€œ%b\nโ€, 10โ€ฒ 1010 # perl -e โ€˜printf โ€œ%d\nโ€, 0b1010โ€ฒ 10 ... #!/bin/bash #hextodec #convert any number of hex numbers to decimal #use "silent" as an argument to get briefer output for subsequent arguments.
Find elsewhere
๐ŸŒ
CoolConversion
coolconversion.com โ€บ home โ€บ math & numbers โ€บ number base converter
BC Hex = 188 Decimal | Conversion with Steps
BC in hex equals 188 in decimal. Learn the conversion with our step-by-step solution and formula explanation.
๐ŸŒ
Linux Hint
linuxhint.com โ€บ convert_hexadecimal_decimal_bash
Convert Hexadecimal to Decimal in Bash โ€“ Linux Hint
In this example, the input value has to give in the command line argument, which will be read by $@. Here, just ibase with 16 value is used to convert hex to the decimal number. #!/bin/bash echo -n "The decimal value of $@=" echo "ibase=16; $@"|bc
๐ŸŒ
DocStore
docstore.mik.ua โ€บ orelly โ€บ unix โ€บ upt โ€บ ch49_02.htm
[Chapter 49] 49.2 bc: Hexadecimal or Binary Conversion
One thing that's really handy to know about bc is how to use it for base conversion ยท By default, bc takes its input and prints its output in decimal. However, you can set either the input or the output to be some other base numbering system - for example, hexadecimal or binary - using the ...
๐ŸŒ
Appuals
appuals.com โ€บ home โ€บ linux โ€บ linux tips
How to Use bc as a Hex Calculator
April 30, 2023 - Type echo โ€˜obase=16;127โ€™ | bc to convert the number 127 to hexadecimal from regular base-10 numbers. Naturally, you can replace that with any whole number. The result youโ€™ll get is 7F, and if you wanted to convert back to regular base-10 you could type echo โ€˜ibase=16;obase=A;7Fโ€™ | bc and push enter.
Top answer
1 of 6
54

What you actually want to say is:

$ echo "ibase=16; C0" | bc
192

for hex-to-decimal, and:

$ echo "obase=16; 192" | bc
C0

for decimal-to-hex.

You don't need to give both ibase and obase for any conversion involving decimal numbers, since these settings default to 10.

You do need to give both for conversions such as binary-to-hex. In that case, I find it easiest to make sense of things if you give obase first:

$ echo "obase=16; ibase=2; 11000000" | bc
C0

If you give ibase first instead, it changes the interpretation of the following obase setting, so that the command has to be:

$ echo "ibase=2; obase=10000; 11000000" | bc
C0

This is because in this order, the obase value is interpreted as a binary number, so you need to give 10000โ‚‚=16 to get output in hex. That's clumsy.


Now letโ€™s work out why your three examples behave as they do.

  1. echo "ibase=F;obase=A;C0" | bc

    180

    That sets the input base to 15 and the output base to 10, since a single-digit value is interpreted in hex, according to POSIX. This asks bc to tell you what C0โ‚โ‚… is in base Aโ‚โ‚…=10, and it is correctly answering 180โ‚โ‚€, though this is certainly not the question you meant to ask.

  2. echo "ibase=F;obase=10;C0" | bc

    C0

    This is a null conversion in base 15.

    Why? First, because the single F digit is interpreted in hex, as I pointed out in the previous example. But now that you've set it to base 15, the following output base setting is interpreted that way, and 10โ‚โ‚…=15, so you have a null conversion from C0โ‚โ‚… to C0โ‚โ‚….

    That's right, the output isn't in hex as you were assuming, it's in base 15!

    You can prove this to yourself by trying to convert F0 instead of C0. Since there is no F digit in base 15, bc clamps it to E0, and gives E0 as the output.

  3. echo "ibase=16; obase=A; C0"

    192

    This is the only one of your three examples that likely has any practical use.

    It is changing the input base to hex first, so that you no longer need to dig into the POSIX spec to understand why A is interpreted as hex, 10 in this case. The only problem with it is that it is redundant to set the output base to Aโ‚โ‚†=10, since that's its default value.

2 of 6
9

Setting ibase means you need to set obase in that same base. Explaining your examples will show this:

echo "ibase=F;obase=A;C0" | bc

You set bc to consider input numbers as represented in base 15 with the "ibase=F". "obase=A" sets output numbers to base 10, which is the default.

bc reads C0 as a base 15 number: C = 12. 12*15 = 180.


echo "ibase=F;obase=10;C0" | bc

In this one, you set input to base 15, and output to 10 - in base 15, so output base is 15. C0 input in base 15 is C0 output in base 15.


echo "ibase=16;obase=A;C0" | bc

Set input to base 16, output to base 10 (A in base 16 is 10 in base 10).

C0 converted to base 10 is: 12*16 = 192


My personal rule is to set obase first, so that I can use base 10. Then set ibase, also using base 10.

Note that bc does have an ironic exception: ibase=A and obase=A always sets input and output to base 10. From the bc man page:

Single digit numbers always have the value of the digit 
regardless of the value of ibase.

This behavior is enshrined in the specification of bc: From the 2004 OpenGroup bc specification:

When either ibase or obase is assigned a single digit value from 
the list in 'Lexical Conventions in bc', the value shall be assumed
in hexadecimal. (For example, ibase=A sets to base ten, regardless 
of the current ibase value.) Otherwise, the behavior is undefined 
when digits greater than or equal to the value of ibase appear in
the input.

That's why the ibase=F setting changed your input base to base 15, and why I recommended to always set the base using base 10. Avoid confusing yourself.

๐ŸŒ
Calculator.net
calculator.net โ€บ home โ€บ math โ€บ hex calculator
Hex Calculator
The hexadecimal number system (hex) functions virtually identically to the decimal and binary systems. Instead of using a base of 10 or 2 respectively, it uses a base of 16. Hex uses 16 digits including 0-9, just as the decimal system does, but also uses the letters A, B, C, D, E, and F (equivalent to a, b, c, d, e, f) to represent the numbers 10-15.
๐ŸŒ
Converter Maniacs
convertermaniacs.com โ€บ numerals โ€บ hexadecimal-to-decimal โ€บ convert-bc-hexadecimal-to-decimal.html
Convert BC hexadecimal to decimal
This page will explain what hexadecimal and decimal numerals are and convert BC hexadecimal to decimal for you. Hexadecimal numerals, such as BC, are made from a set of sixteen digits. These digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. Decimal numerals are made from a set of ten digits.
Top answer
1 of 2
5

It's not just that number, it's any number over 7fffffffffffffff, because it's using 64-bit integers and that's the largest one. 16-digit numbers over that wrap around and become negative (because of two's complement representation of signed integers):

$ echo $((16#7fffffffffffffff))
9223372036854775807
$ echo $((16#7fffffffffffffff + 1))
-9223372036854775808
$ echo $((16#8000000000000000))
-9223372036854775808

Past ffffffffffffffff (aka -1), it wraps back to zero:

$ echo $((16#ffffffffffffffff))
-1
$ echo $((16#ffffffffffffffff + 1))
0
$ echo $((16#10000000000000000))
0

Net result: only the last 16 hex digits actually matter; anything past that gets dropped off the high end of the 64-bit integer representation:

$ echo $((16#0000000000000010))
16
$ echo $((16#10000000000000010))
16
$ echo $((16#ffffffff0000000000000010))
16

Since 1553255926290448384 is 17 digits long, the first digit is being dropped off in this way:

$ echo $((16#1158e460913d00000))
1553255926290448384
$ echo $((16#158e460913d00000))
1553255926290448384
$ echo $((16#121345158e460913d00000))
1553255926290448384
2 of 2
3

You can do what you are looking to do using bc as a base conversion with a short script:

#!/bin/bash

## validate sufficient input
test -n "$1" || {
    printf "\n error: insufficient input. usage:  %s num [obase (2)] [ibase (10)]\n\n" "${0//*\//}"
    exit 1
}

## test for help
test "$1" = "-h" || test "$1" = "--help" && {
    printf "\n  usage:  %s num [obase (2)] [ibase (10)] -- to convert number\n\n" "${0//*\//}"
    exit 0
}

## validate numeric value given for conversion (bash only test)
ival="${1^^}"
[[ $ival =~ [^0-9A-F] ]] && {
    printf "\n error: invalid input. Input must be within upper/lower case hex character set [0-9A-Fa-f]\n\n"
    exit 1
}

ob=${2:-2}
ib=${3:-10}

# set obase first before ibase -- or weird things happen.
printf "obase=%d; ibase=%d; %s\n" $ob $ib $ival | bc

Example Use/Output

$ bash hex2dec.sh -h

  usage:  hex2dec.sh num [obase (2)] [ibase (10)] -- to convert number

Using your example:

$ bash hex2dec.sh 1158e460913d00000 10 16
20000000000000000000

Also handy if you want it in binary as well:

$ bash hex2dec.sh 1158e460913d00000 2 16
10001010110001110010001100000100100010011110100000000000000000000