@@ -0,0 +1,971 @@
<!DOCTYPE html>
< html lang = "en" dir = "ltr" > < head > < script src = "/livereload.js?mindelay=10&v=2&port=1313&path=livereload" data-no-instant defer > < / script >
< meta charset = "utf-8" / >
< meta name = "viewport" content = "width=device-width, initial-scale=1.0" / > < meta name = "robots" content = "noindex, nofollow" / >
< link rel = "icon shortcut" href = "/favicon.ico" sizes = "32x32" / >
< link rel = "icon" href = "/favicon.svg" type = "image/svg+xml" id = "favicon-svg" / >
< link rel = "icon" href = "/favicon-16x16.png" type = "image/png" sizes = "16x16" / >
< link rel = "icon" href = "/favicon-32x32.png" type = "image/png" sizes = "32x32" / >
< link rel = "apple-touch-icon" href = "/apple-touch-icon.png" sizes = "180x180" / >
< link fetchpriority = "low" href = "/site.webmanifest" rel = "manifest" / >
< title > SumBigDecimalHex – CodeJava< / title >
< meta name = "description" content = "Task Input data fits into BigDecimal data type There are decimal and hexadecimal numbers in input Hexadecimal numbers has 0x prefix, so for example 0xbsc equals 11·10⁻¹² (mantissa and exponent are integers) Input is case insensitive Class should be named SumBigDecimalHex Solution This is the hardest (and last) modification for this homework.
Let’ s modify our SumDoubleHex parseNumber method. This is what it looks now
static double parseNumber(StringBuilder number) { if (!number.isEmpty()) { String numberString = number.toString(); if ( numberString.startsWith("0x") || numberString.startsWith("0X") ) { if (numberString.contains(".")) { return Double.parseDouble(numberString); } return Long.parseLong(numberString.substring(2), 16); } else { return Double.parseDouble(numberString); } } else { return 0; } } Let’ s make some small changes:" / > < link rel = "canonical" href = "http://localhost:1313/courses/prog-intro/homeworks/sum/sumbigdecimalhex/" itemprop = "url" / >
< meta property = "og:title" content = "SumBigDecimalHex" >
< meta
property = "og:description"
content = "
Learn Java programming
" >
< meta
property = "og:type"
content = "
website
" >
< meta property = "og:url" content = "http://localhost:1313/courses/prog-intro/homeworks/sum/sumbigdecimalhex/" >
< meta itemprop = "name" content = "SumBigDecimalHex" >
< meta itemprop = "description" content = "Task Input data fits into BigDecimal data type There are decimal and hexadecimal numbers in input Hexadecimal numbers has 0x prefix, so for example 0xbsc equals 11·10⁻¹² (mantissa and exponent are integers) Input is case insensitive Class should be named SumBigDecimalHex Solution This is the hardest (and last) modification for this homework.
Let’ s modify our SumDoubleHex parseNumber method. This is what it looks now
static double parseNumber(StringBuilder number) { if (!number.isEmpty()) { String numberString = number.toString(); if ( numberString.startsWith("0x") || numberString.startsWith("0X") ) { if (numberString.contains(".")) { return Double.parseDouble(numberString); } return Long.parseLong(numberString.substring(2), 16); } else { return Double.parseDouble(numberString); } } else { return 0; } } Let’ s make some small changes:" >
< meta itemprop = "wordCount" content = "1294" >
< meta name = "twitter:card" content = "summary" >
< meta name = "twitter:title" content = "SumBigDecimalHex" >
< meta name = "twitter:description" content = "Task Input data fits into BigDecimal data type There are decimal and hexadecimal numbers in input Hexadecimal numbers has 0x prefix, so for example 0xbsc equals 11·10⁻¹² (mantissa and exponent are integers) Input is case insensitive Class should be named SumBigDecimalHex Solution This is the hardest (and last) modification for this homework.
Let’ s modify our SumDoubleHex parseNumber method. This is what it looks now
static double parseNumber(StringBuilder number) { if (!number.isEmpty()) { String numberString = number.toString(); if ( numberString.startsWith("0x") || numberString.startsWith("0X") ) { if (numberString.contains(".")) { return Double.parseDouble(numberString); } return Long.parseLong(numberString.substring(2), 16); } else { return Double.parseDouble(numberString); } } else { return 0; } } Let’ s make some small changes:" >
< link href = "/css/compiled/main.css" rel = "stylesheet" / >
< link href = "/css/variables.css" rel = "stylesheet" / >
< link href = "/css/custom.css" rel = "stylesheet" / >
< script >
function setTheme ( theme ) {
document . documentElement . classList . remove ( "light" , "dark" ) ;
if ( theme !== "light" && theme !== "dark" ) {
theme = window . matchMedia ( "(prefers-color-scheme: dark)" ) . matches ? "dark" : "light" ;
}
document . documentElement . classList . add ( theme ) ;
document . documentElement . style . colorScheme = theme ;
}
setTheme ( "color-theme" in localStorage ? localStorage . getItem ( "color-theme" ) : 'system' )
< / script >
< script >
if ( localStorage . getItem ( 'banner-closed' ) ) {
document . documentElement . style . setProperty ( "--hextra-banner-height" , "0px" ) ;
document . documentElement . classList . add ( "hextra-banner-hidden" ) ;
}
< / script >
< link rel = "stylesheet" href = "/css/katex.cd310c44e654e5e3f53ee852cd87614ce56a1801f32c9bb1bfba4da39c9da3c95b6d176008ecb638b7b9808d26b4aaaa464b2b1bed7069bb99ca3670cdba978d.css" integrity = "sha512-zTEMROZU5eP1PuhSzYdhTOVqGAHzLJuxv7pNo5ydo8lbbRdgCOy2OLe5gI0mtKqqRksrG+1wabuZyjZwzbqXjQ==" / >
< / head >
< body > < div class = "hextra-nav-container hx:sticky hx:top-0 hx:z-20 hx:w-full hx:bg-transparent hx:print:hidden" >
< div
class = "hextra-nav-container-blur hx:pointer-events-none hx:absolute hx:z-[-1] hx:h-full hx:w-full hx:bg-white hx:dark:bg-dark hx:shadow-[0_2px_4px_rgba(0,0,0,.02),0_1px_0_rgba(0,0,0,.06)] hx:contrast-more:shadow-[0_0_0_1px_#000] hx:dark:shadow-[0_-1px_0_rgba(255,255,255,.1)_inset] hx:contrast-more:dark:shadow-[0_0_0_1px_#fff]"
> < / div >
< nav class = "hextra-max-navbar-width hx:mx-auto hx:flex hx:items-center hx:justify-end hx:gap-2 hx:h-16 hx:px-6" >
< a class = "hx:flex hx:items-center hx:hover:opacity-75 hx:ltr:mr-auto hx:rtl:ml-auto" href = "/" >
< img class = "hx:mr-2 hx:block hx:dark:hidden" src = "/images/logo.svg" alt = "Logo" height = "20" width = "20" / >
< img class = "hx:mr-2 hx:hidden hx:dark:block" src = "/images/logo.svg" alt = "Dark Logo" height = "20" width = "20" / >
< span class = "hx:mr-2 hx:font-extrabold hx:inline hx:select-none" title = "CodeJava" > CodeJava< / span >
< / a >
< a
title = ""
href = "/courses"
class = "hx:text-sm hx:contrast-more:text-gray-700 hx:contrast-more:dark:text-gray-100 hx:relative hx:-ml-2 hx:hidden hx:whitespace-nowrap hx:p-2 hx:md:inline-flex hx:items-center hx:gap-1 hx:font-medium"
> < span class = "hx:text-center" > Courses< / span >
< / a > < div class = "hextra-search-wrapper hx:relative hx:md:w-64" >
< div class = "hx:relative hx:flex hx:items-center hx:text-gray-900 hx:contrast-more:text-gray-800 hx:dark:text-gray-300 hx:contrast-more:dark:text-gray-300" >
< input
placeholder = "Search..."
class = "hextra-search-input hx:focus:hextra-focus hx:block hx:w-full hx:appearance-none hx:rounded-lg hx:px-3 hx:py-2 hx:transition-colors hx:text-base hx:leading-tight hx:md:text-sm hx:bg-black/[.05] hx:dark:bg-gray-50/10 hx:focus:bg-white hx:dark:focus:bg-dark hx:placeholder:text-gray-500 hx:dark:placeholder:text-gray-400 hx:contrast-more:border hx:contrast-more:border-current"
type = "search"
value = ""
spellcheck = "false"
/ >
< kbd
class = "hx:absolute hx:my-1.5 hx:select-none hx:ltr:right-1.5 hx:rtl:left-1.5 hx:h-5 hx:rounded-sm hx:bg-white hx:px-1.5 hx:font-mono hx:text-[10px] hx:font-medium hx:text-gray-500 hx:border hx:border-gray-200 hx:dark:border-gray-100/20 hx:dark:bg-dark/50 hx:contrast-more:border-current hx:contrast-more:text-current hx:contrast-more:dark:border-current hx:items-center hx:gap-1 hx:transition-opacity hx:pointer-events-none hx:hidden hx:sm:flex"
>
CTRL K
< / kbd >
< / div >
< div >
< ul
class = "hextra-search-results hextra-scrollbar hx:hidden hx:border hx:border-gray-200 hx:bg-white hx:text-gray-100 hx:dark:border-neutral-800 hx:dark:bg-neutral-900 hx:absolute hx:top-full hx:z-20 hx:mt-2 hx:overflow-auto hx:overscroll-contain hx:rounded-xl hx:py-2.5 hx:shadow-xl hx:max-h-[min(calc(50vh-11rem-env(safe-area-inset-bottom)),400px)] hx:md:max-h-[min(calc(100vh-5rem-env(safe-area-inset-bottom)),400px)] hx:inset-x-0 hx:ltr:md:left-auto hx:rtl:md:right-auto hx:contrast-more:border hx:contrast-more:border-gray-900 hx:contrast-more:dark:border-gray-50 hx:w-screen hx:min-h-[100px] hx:max-w-[min(calc(100vw-2rem),calc(100%+20rem))]"
style = "transition: max-height 0.2s ease 0s;"
> < / ul >
< / div >
< / div >
< button type = "button" aria-label = "Menu" class = "hextra-hamburger-menu hx:cursor-pointer hx:-mr-2 hx:rounded-sm hx:p-2 hx:active:bg-gray-400/20 hx:md:hidden" > < svg height = 24 fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" > < g > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M4 8H20" > < / path > < / g > < g > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M4 16H20" > < / path > < / g > < / svg > < / button >
< / nav >
< / div >
< div class = 'hx:mx-auto hx:flex hextra-max-page-width' >
< aside class = "hextra-sidebar-container hx:flex hx:flex-col hx:print:hidden hx:md:top-16 hx:md:shrink-0 hx:md:w-64 hx:md:self-start hx:max-md:[transform:translate3d(0,-100%,0)] hx:md:sticky" >
< div class = "hx:px-4 hx:pt-4 hx:md:hidden" >
< div class = "hextra-search-wrapper hx:relative hx:md:w-64" >
< div class = "hx:relative hx:flex hx:items-center hx:text-gray-900 hx:contrast-more:text-gray-800 hx:dark:text-gray-300 hx:contrast-more:dark:text-gray-300" >
< input
placeholder = "Search..."
class = "hextra-search-input hx:focus:hextra-focus hx:block hx:w-full hx:appearance-none hx:rounded-lg hx:px-3 hx:py-2 hx:transition-colors hx:text-base hx:leading-tight hx:md:text-sm hx:bg-black/[.05] hx:dark:bg-gray-50/10 hx:focus:bg-white hx:dark:focus:bg-dark hx:placeholder:text-gray-500 hx:dark:placeholder:text-gray-400 hx:contrast-more:border hx:contrast-more:border-current"
type = "search"
value = ""
spellcheck = "false"
/ >
< kbd
class = "hx:absolute hx:my-1.5 hx:select-none hx:ltr:right-1.5 hx:rtl:left-1.5 hx:h-5 hx:rounded-sm hx:bg-white hx:px-1.5 hx:font-mono hx:text-[10px] hx:font-medium hx:text-gray-500 hx:border hx:border-gray-200 hx:dark:border-gray-100/20 hx:dark:bg-dark/50 hx:contrast-more:border-current hx:contrast-more:text-current hx:contrast-more:dark:border-current hx:items-center hx:gap-1 hx:transition-opacity hx:pointer-events-none hx:hidden hx:sm:flex"
>
CTRL K
< / kbd >
< / div >
< div >
< ul
class = "hextra-search-results hextra-scrollbar hx:hidden hx:border hx:border-gray-200 hx:bg-white hx:text-gray-100 hx:dark:border-neutral-800 hx:dark:bg-neutral-900 hx:absolute hx:top-full hx:z-20 hx:mt-2 hx:overflow-auto hx:overscroll-contain hx:rounded-xl hx:py-2.5 hx:shadow-xl hx:max-h-[min(calc(50vh-11rem-env(safe-area-inset-bottom)),400px)] hx:md:max-h-[min(calc(100vh-5rem-env(safe-area-inset-bottom)),400px)] hx:inset-x-0 hx:ltr:md:left-auto hx:rtl:md:right-auto hx:contrast-more:border hx:contrast-more:border-gray-900 hx:contrast-more:dark:border-gray-50 hx:w-screen hx:min-h-[100px] hx:max-w-[min(calc(100vw-2rem),calc(100%+20rem))]"
style = "transition: max-height 0.2s ease 0s;"
> < / ul >
< / div >
< / div >
< / div >
< div class = "hextra-scrollbar hx:overflow-y-auto hx:overflow-x-hidden hx:p-4 hx:grow hx:md:h-[calc(100vh-var(--navbar-height)-var(--menu-height))]" >
< ul class = "hx:flex hx:flex-col hx:gap-1 hx:md:hidden" >
< li class = "open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/"
> Courses
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a > < div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/spring-boot/"
> Spring Boot
< / a >
< / li > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/"
> Introduction to Programming in Java
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/"
> Homeworks
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/"
> Sum
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hextra-sidebar-active-item hx:bg-primary-100 hx:font-semibold hx:text-primary-800 hx:contrast-more:border hx:contrast-more:border-primary-500 hx:dark:bg-primary-400/10 hx:dark:text-primary-600 hx:contrast-more:dark:border-primary-500"
href = "/courses/prog-intro/homeworks/sum/sumbigdecimalhex/"
> SumBigDecimalHex
< / a >
< ul class = 'hx:flex hx:flex-col hx:gap-1 hx:relative hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:dark:before:bg-neutral-800 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:pr-3 hx:rtl:before:right-0 hx:ltr:ml-3 hx:rtl:mr-3' > < li >
< a
href = "#solution"
class = "hx:flex hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [word-break:break-word] hx:cursor-pointer [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] hx:contrast-more:border hx:gap-2 hx:before:opacity-25 hx:before:content-['#'] hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:text-gray-900 hx:contrast-more:dark:text-gray-50 hx:contrast-more:border-transparent hx:contrast-more:hover:border-gray-900 hx:contrast-more:dark:hover:border-gray-50"
> Solution< / a >
< / li >
< / ul >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumbigintegeroctal/"
> SumBigIntegerOctal
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumdouble/"
> SumDouble
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumdoublehex/"
> SumDoubleHex
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumhex/"
> SumHex
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumlongoctal/"
> SumLongOctal
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/conclusion/"
> Summing Up
< / a >
< / li > < / ul >
< / div >
< / li > < / ul >
< / div >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/lectures/"
> Lectures
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/lectures/intro/"
> Lecture 1. Introduction
< / a >
< / li > < / ul >
< / div >
< / li > < / ul >
< / div >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/paradigms/"
> Paradgims of Programming
< / a >
< / li > < / ul >
< / div > < / li >
< / ul >
< ul class = "hx:flex hx:flex-col hx:gap-1 hx:max-md:hidden" >
< li class = "" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/spring-boot/"
> Spring Boot
< / a > < / li >
< li class = "open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/"
> Introduction to Programming in Java
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a > < div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/"
> Homeworks
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/"
> Sum
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col open" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hextra-sidebar-active-item hx:bg-primary-100 hx:font-semibold hx:text-primary-800 hx:contrast-more:border hx:contrast-more:border-primary-500 hx:dark:bg-primary-400/10 hx:dark:text-primary-600 hx:contrast-more:dark:border-primary-500"
href = "/courses/prog-intro/homeworks/sum/sumbigdecimalhex/"
> SumBigDecimalHex
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumbigintegeroctal/"
> SumBigIntegerOctal
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumdouble/"
> SumDouble
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumdoublehex/"
> SumDoubleHex
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumhex/"
> SumHex
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/sumlongoctal/"
> SumLongOctal
< / a >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/homeworks/sum/conclusion/"
> Summing Up
< / a >
< / li > < / ul >
< / div >
< / li > < / ul >
< / div >
< / li > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/lectures/"
> Lectures
< span class = "hextra-sidebar-collapsible-button" > < svg fill = "none" viewBox = "0 0 24 24" stroke = "currentColor" class = "hx:h-[18px] hx:min-w-[18px] hx:rounded-xs hx:p-0.5 hx:hover:bg-gray-800/5 hx:dark:hover:bg-gray-100/5" > < path stroke-linecap = "round" stroke-linejoin = "round" stroke-width = "2" d = "M9 5l7 7-7 7" class = "hx:origin-center hx:transition-transform hx:rtl:-rotate-180" > < / path > < / svg > < / span >
< / a >
< div class = "hx:ltr:pr-0 hx:overflow-hidden" >
< ul class = 'hx:relative hx:flex hx:flex-col hx:gap-1 hx:before:absolute hx:before:inset-y-1 hx:before:w-px hx:before:bg-gray-200 hx:before:content-[""] hx:ltr:ml-3 hx:ltr:pl-3 hx:ltr:before:left-0 hx:rtl:mr-3 hx:rtl:pr-3 hx:rtl:before:right-0 hx:dark:before:bg-neutral-800' > < li class = "hx:flex hx:flex-col " > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/prog-intro/lectures/intro/"
> Lecture 1. Introduction
< / a >
< / li > < / ul >
< / div >
< / li > < / ul >
< / div > < / li >
< li class = "" > < a
class = "hx:flex hx:items-center hx:justify-between hx:gap-2 hx:cursor-pointer hx:rounded-sm hx:px-2 hx:py-1.5 hx:text-sm hx:transition-colors [-webkit-tap-highlight-color:transparent] [-webkit-touch-callout:none] [word-break:break-word]
hx:text-gray-500 hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:contrast-more:border hx:contrast-more:border-transparent hx:contrast-more:text-gray-900 hx:contrast-more:hover:border-gray-900 hx:dark:text-neutral-400 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:contrast-more:dark:text-gray-50 hx:contrast-more:dark:hover:border-gray-50"
href = "/courses/paradigms/"
> Paradgims of Programming
< / a > < / li >
< / ul >
< / div >
< div class = " hx:sticky hx:bottom-0 hx:max-h-(--menu-height) hx:bg-white hx:dark:bg-dark hx:mx-4 hx:py-4 hx:shadow-[0_-12px_16px_#fff] hx:flex hx:items-center hx:gap-2 hx:border-gray-200 hx:dark:border-neutral-800 hx:dark:shadow-[0_-12px_16px_#111] hx:contrast-more:border-neutral-400 hx:contrast-more:shadow-none hx:contrast-more:dark:shadow-none hx:border-t" data-toggle-animation = "show" > < div class = "hx:flex hx:grow hx:flex-col" > < div class = "hx:flex hx:justify-items-start hx:group" data-theme = "light" >
< button
title = "Change theme"
data-state = "closed"
data-location = "bottom"
class = "hextra-theme-toggle hx:cursor-pointer hx:rounded-md hx:text-left hx:font-medium hx:h-7 hx:px-2 hx:text-xs hx:hover:bg-gray-100 hx:hover:text-gray-900 hx:dark:hover:bg-primary-100/5 hx:dark:hover:text-gray-50 hx:font-medium hx:text-gray-600 hx:transition-colors hx:dark:text-gray-400 hx:grow"
type = "button"
aria-label = "Change theme"
>
< div class = "hx:flex hx:items-center hx:gap-2 hx:capitalize" > < svg height = 12 class = "hx:group-data-[theme=dark]:hidden hx:group-data-[theme=system]:hidden" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z" / > < / svg > < span class = "hx:group-data-[theme=dark]:hidden hx:group-data-[theme=system]:hidden" > Light< / span > < svg height = 12 class = "hx:group-data-[theme=light]:hidden hx:group-data-[theme=system]:hidden" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z" / > < / svg > < span class = "hx:group-data-[theme=light]:hidden hx:group-data-[theme=system]:hidden" > Dark< / span > < svg height = 12 class = "hx:group-data-[theme=dark]:hidden hx:group-data-[theme=light]:hidden" xmlns = "http://www.w3.org/2000/svg" viewBox = "0 0 24 24" fill = "currentColor" >
< path d = "M 11.996094,2 C 6.4986225,2.0192368 2.03125,6.5024993 2.03125,12 c 0,5.497501 4.4673725,9.980763 9.964844,10 H 12 12.0039 c 5.497471,-0.01924 9.964844,-4.502499 9.964844,-10 0,-5.4975007 -4.467373,-9.9807632 -9.964844,-10 H 12 Z M 12,4 c 4.417218,0.017598 7.96875,3.5822356 7.96875,8 0,4.417764 -3.551532,7.982402 -7.96875,8 z" / >
< / svg >
< span class = "hx:group-data-[theme=dark]:hidden hx:group-data-[theme=light]:hidden" > System< / span > < / div >
< / button >
< ul
class = "hextra-theme-toggle-options hx:hidden hx:z-20 hx:max-h-64 hx:overflow-auto hx:rounded-md hx:ring-1 hx:ring-black/5 hx:bg-white hx:py-1 hx:text-sm hx:shadow-lg hx:dark:ring-white/20 hx:dark:bg-neutral-800"
style = "position: fixed; inset: auto auto 0px 0px; margin: 0px; min-width: 100px;"
data-theme = "light"
>
< li class = "hx:flex hx:flex-col" >
< p
data-item = "light"
class = "hx:text-gray-800 hx:dark:text-gray-100 hx:hover:bg-primary-50 hx:hover:text-primary-600 hx:hover:dark:bg-primary-500/10 hx:hover:dark:text-primary-600 hx:relative hx:cursor-pointer hx:whitespace-nowrap hx:py-1.5 hx:transition-colors hx:ltr:pl-3 hx:ltr:pr-9 hx:rtl:pr-3 hx:rtl:pl-9"
>
Light
< span class = "hx:absolute hx:inset-y-0 hx:flex hx:items-center hx:ltr:right-3 hx:rtl:left-3 hx:group-data-[theme=dark]:hidden hx:group-data-[theme=system]:hidden" > < svg height = 1em width = 1em xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M5 13l4 4L19 7" / > < / svg > < / span >
< / p >
< / li >
< li class = "hx:flex hx:flex-col" >
< p
data-item = "dark"
class = "hx:text-gray-800 hx:dark:text-gray-100 hx:hover:bg-primary-50 hx:hover:text-primary-600 hx:hover:dark:bg-primary-500/10 hx:hover:dark:text-primary-600 hx:relative hx:cursor-pointer hx:whitespace-nowrap hx:py-1.5 hx:transition-colors hx:ltr:pl-3 hx:ltr:pr-9 hx:rtl:pr-3 hx:rtl:pl-9"
>
Dark
< span class = "hx:absolute hx:inset-y-0 hx:flex hx:items-center hx:ltr:right-3 hx:rtl:left-3 hx:group-data-[theme=light]:hidden hx:group-data-[theme=system]:hidden" > < svg height = 1em width = 1em xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M5 13l4 4L19 7" / > < / svg > < / span >
< / p >
< / li >
< li class = "hx:flex hx:flex-col" >
< p
data-item = "system"
class = "hx:text-gray-800 hx:dark:text-gray-100 hx:hover:bg-primary-50 hx:hover:text-primary-600 hx:hover:dark:bg-primary-500/10 hx:hover:dark:text-primary-600 hx:relative hx:cursor-pointer hx:whitespace-nowrap hx:py-1.5 hx:transition-colors hx:ltr:pl-3 hx:ltr:pr-9 hx:rtl:pr-3 hx:rtl:pl-9"
>
System
< span class = "hx:absolute hx:inset-y-0 hx:flex hx:items-center hx:ltr:right-3 hx:rtl:left-3 hx:group-data-[theme=dark]:hidden hx:group-data-[theme=light]:hidden" > < svg height = 1em width = 1em xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M5 13l4 4L19 7" / > < / svg > < / span >
< / p >
< / li >
< / ul >
< / div > < / div > < / div > < / aside >
< nav class = "hextra-toc hx:order-last hx:hidden hx:w-64 hx:shrink-0 hx:xl:block hx:print:hidden hx:px-4" aria-label = "table of contents" >
< div class = "hextra-scrollbar hx:sticky hx:top-16 hx:overflow-y-auto hx:pr-4 hx:pt-6 hx:text-sm [hyphens:auto] hx:max-h-[calc(100vh-var(--navbar-height)-env(safe-area-inset-bottom))] hx:ltr:-mr-4 hx:rtl:-ml-4" > < p class = "hx:mb-4 hx:font-semibold hx:tracking-tight" > On this page< / p > < ul >
< li class = "hx:my-2 hx:scroll-my-6 hx:scroll-py-6" >
< a class = "hx:font-medium hx:inline-block hx:text-gray-500 hx:hover:text-gray-900 hx:dark:text-gray-400 hx:dark:hover:text-gray-300 hx:contrast-more:text-gray-900 hx:contrast-more:underline hx:contrast-more:dark:text-gray-50 hx:w-full hx:break-words" href = "#solution" > Solution
< / a >
< / li > < / ul >
< div class = "hx:mt-8 hx:border-t hx:bg-white hx:pt-8 hx:shadow-[0_-12px_16px_white] hx:dark:bg-dark hx:dark:shadow-[0_-12px_16px_#111] hx:sticky hx:bottom-0 hx:flex hx:flex-col hx:items-start hx:gap-2 hx:pb-8 hx:border-gray-200 hx:dark:border-neutral-800 hx:contrast-more:border-t hx:contrast-more:border-neutral-400 hx:contrast-more:shadow-none hx:contrast-more:dark:border-neutral-400" >
< button aria-hidden = "true" id = "backToTop" onClick = "scrollUp();" class = "hx:cursor-pointer hx:transition-all hx:duration-75 hx:opacity-0 hx:text-xs hx:font-medium hx:text-gray-500 hx:hover:text-gray-900 hx:dark:text-gray-400 hx:dark:hover:text-gray-100 hx:contrast-more:text-gray-800 hx:contrast-more:dark:text-gray-50" >
< span > Scroll to top< / span >
< svg xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "1.5" stroke = "currentColor" class = "hx:inline hx:ltr:ml-1 hx:rtl:mr-1 hx:h-3.5 hx:w-3.5 hx:rounded-full hx:border hx:border-gray-500 hx:hover:border-gray-900 hx:dark:border-gray-400 hx:dark:hover:border-gray-100 hx:contrast-more:border-gray-800 hx:contrast-more:dark:border-gray-50" >
< path stroke-linecap = "round" stroke-linejoin = "round" d = "M4.5 15.75l7.5-7.5 7.5 7.5" / >
< / svg >
< / button >
< / div >
< / div >
< / nav >
< article class = "hx:w-full hx:break-words hx:flex hx:min-h-[calc(100vh-var(--navbar-height))] hx:min-w-0 hx:justify-center hx:pb-8 hx:pr-[calc(env(safe-area-inset-right)-1.5rem)]" >
< main class = "hx:w-full hx:min-w-0 hx:max-w-6xl hx:px-6 hx:pt-4 hx:md:px-12" >
< div class = "content" >
< h1 > SumBigDecimalHex< / h1 >
< h1 > Task< / h1 > < ul >
< li > Input data fits into < a href = "https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html" target = "_blank" rel = "noopener" > BigDecimal< / a > data type< / li >
< li > There are decimal and hexadecimal numbers in input< / li >
< li > Hexadecimal numbers has < code > 0x< / code > prefix, so for example < code > 0xbsc< / code > equals < code > 11·10⁻¹²< / code > (mantissa and exponent are integers)< / li >
< li > Input is case insensitive< / li >
< li > Class should be named < code > SumBigDecimalHex< / code > < / li >
< / ul >
< h2 > Solution< span class = "hx:absolute hx:-mt-20" id = "solution" > < / span >
< a href = "#solution" class = "subheading-anchor" aria-label = "Permalink for this section" > < / a > < / h2 > < p > This is the hardest (and last) modification for this homework.< / p >
< p > Let’ s modify our < code > SumDoubleHex< / code > < code > parseNumber< / code > method. This is what it looks now< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > < span style = "color:#66d9ef" > double< / span > < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > number.< span style = "color:#a6e22e" > isEmpty< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > String numberString < span style = "color:#f92672" > =< / span > number.< span style = "color:#a6e22e" > toString< / span > ();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (
< / span > < / span > < span style = "display:flex;" > < span > numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0x" < / span > ) < span style = "color:#f92672" > ||< / span > numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0X" < / span > )
< / span > < / span > < span style = "display:flex;" > < span > ) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > contains< / span > (< span style = "color:#e6db74" > " ." < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > Double.< span style = "color:#a6e22e" > parseDouble< / span > (numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > Long.< span style = "color:#a6e22e" > parseLong< / span > (numberString.< span style = "color:#a6e22e" > substring< / span > (2), 16);
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > Double.< span style = "color:#a6e22e" > parseDouble< / span > (numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > 0;
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > Let’ s make some small changes:< / p >
< p > Firstly, let’ s change the output data type to < code > BigDecimal< / code > . So we will change this line< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > < span style = "color:#66d9ef" > double< / span > < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > to this< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > BigDecimal < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > Also let’ s change this line from the parsing of a decimal number option< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > Double.< span style = "color:#a6e22e" > parseDouble< / span > (numberString);< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > to< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(numberString);< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > We will change this line< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > 0;< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > to< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > BigDecimal.< span style = "color:#a6e22e" > ZERO< / span > ;< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > as we did almost the same thing for < code > SumBigIntegerOctal< / code > modification.< / p >
< p > Also let’ s change our < code > numberString< / code > to lowercase letters just for convenience< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < pre > < code > String numberString = number.toString().toLowerCase();< / code > < / pre > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Here we are using < a href = "https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#toLowerCase--" target = "_blank" rel = "noopener" > < code > String.toLowerCase()< / code > < / a > method that converts all the characters to lower case.< / p > < / div >
< / div >
< / div >
< p > So our code will currently look like this< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > BigDecimal < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > number.< span style = "color:#a6e22e" > isEmpty< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > String numberString < span style = "color:#f92672" > =< / span > number.< span style = "color:#a6e22e" > toString< / span > ().< span style = "color:#a6e22e" > toLowerCase< / span > (); < span style = "color:#75715e" > // toLowerCase() added< / span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0x" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > numberString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (2);
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > ( < span style = "color:#75715e" > /* numberString has " s" in it */< / span > ) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > /* somehow parse number */< / span >
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > /* somehow parse number */< / span >
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > BigDecimal.< span style = "color:#a6e22e" > ZERO< / span > ;
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Notice, that we no longer need to check for < code > numberString< / code > to begin with < code > " 0X" < / code > . Since there can’ t be an upper case letter in the < code > numberString< / code > after converting all of its letters to lower case.< / p > < / div >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Also in this line< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > numberString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (2);< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > we strip off first two symbols (< code > 0x< / code > ) in order for correct parsing later.< / p > < / div >
< / div >
< / div >
< p > Let’ s solve our “ comments” one-by-one.< / p >
< p > The easiest is to understand if there is an < code > " s" < / code > in < code > numberString< / code > . We can do so using < a href = "https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#contains-java.lang.CharSequence-" target = "_blank" rel = "noopener" > < code > String.contains(CharSequence s)< / code > < / a > that returns true if and only if this string contains the specified sequence of char values. In our case the sequence of values will be < code > " s" < / code > .< / p >
< p > Let’ s apply this logic to our method< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > BigDecimal < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > number.< span style = "color:#a6e22e" > isEmpty< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > String numberString < span style = "color:#f92672" > =< / span > number.< span style = "color:#a6e22e" > toString< / span > ().< span style = "color:#a6e22e" > toLowerCase< / span > ();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0x" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > numberString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (2);
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > contains< / span > (< span style = "color:#e6db74" > " s" < / span > )) { < span style = "color:#75715e" > // < --< / span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > /* somehow parse number */< / span >
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > /* somehow parse number */< / span >
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > BigDecimal.< span style = "color:#a6e22e" > ZERO< / span > ;
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Again, we are not checking for upper case < code > " S" < / code > , since there are no upper case letters in < code > numberString< / code > because we used < code > .toLowerCase()< / code > .< / p > < / div >
< / div >
< / div >
< p > Okay, now let’ s parse our number if it doesn’ t contain < code > " s" < / code > . It’ s actually very simple. First we need to convert it to < code > BigInteger< / code > and then pass the result to < code > BigDecimal< / code > . It will look like this< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#75715e" > // using 16 to convert from hexadecimal to decimal < / span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > // and only then passing to BigDecimal< / span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(< span style = "color:#66d9ef" > new< / span > BigInteger(numberString, 16)); < / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-purple-200 hx:bg-purple-100 hx:text-purple-900 hx:dark:border-purple-200/30 hx:dark:bg-purple-900/30 hx:dark:text-purple-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Important< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Here, we don’ t assign < code > BigInteger< / code > object to any variable so it is used only for conversion from hexadecimal to decimal. After it’ s value is passed to < code > BigDecimal< / code > a garbage collector can come and destroy it, since there is no way to access it anymore.< / p > < / div >
< / div >
< / div >
< p > We have only one “ unsolved comment” left, but it’ s going to require a bit of theory. So basically < code > s< / code > splits our number in two parts: everything on the left is called a mantissa and on the right is exponent. So the form is basically the following< / p >
< span class = "katex-display" > < span class = "katex" > < span class = "katex-mathml" > < math xmlns = "http://www.w3.org/1998/Math/MathML" display = "block" > < semantics > < mrow > < mn > 0< / mn > < mi > x< / mi > < mo stretchy = "false" > {< / mo > < mi > m< / mi > < mi > a< / mi > < mi > n< / mi > < mi > t< / mi > < mi > i< / mi > < mi > s< / mi > < mi > s< / mi > < mi > a< / mi > < mo stretchy = "false" > }< / mo > < mi > s< / mi > < mo stretchy = "false" > {< / mo > < mi > e< / mi > < mi > x< / mi > < mi > p< / mi > < mi > o< / mi > < mi > n< / mi > < mi > e< / mi > < mi > n< / mi > < mi > t< / mi > < mo stretchy = "false" > }< / mo > < / mrow > < annotation encoding = "application/x-tex" >
0x\{mantissa\}s\{exponent\}
< / annotation > < / semantics > < / math > < / span > < span class = "katex-html" aria-hidden = "true" > < span class = "base" > < span class = "strut" style = "height:1em;vertical-align:-0.25em;" > < / span > < span class = "mord" > 0< / span > < span class = "mord mathnormal" > x< / span > < span class = "mopen" > {< / span > < span class = "mord mathnormal" > man< / span > < span class = "mord mathnormal" > t< / span > < span class = "mord mathnormal" > i< / span > < span class = "mord mathnormal" > ss< / span > < span class = "mord mathnormal" > a< / span > < span class = "mclose" > }< / span > < span class = "mord mathnormal" > s< / span > < span class = "mopen" > {< / span > < span class = "mord mathnormal" > e< / span > < span class = "mord mathnormal" > x< / span > < span class = "mord mathnormal" > p< / span > < span class = "mord mathnormal" > o< / span > < span class = "mord mathnormal" > n< / span > < span class = "mord mathnormal" > e< / span > < span class = "mord mathnormal" > n< / span > < span class = "mord mathnormal" > t< / span > < span class = "mclose" > }< / span > < / span > < / span > < / span > < / span > < p > In order to get the number we will first need to convert each part from hexadecimal to decimal. Exponent represents decimal places. For example < code > 0xABs02< / code > : < code > AB< / code > in hex equals 171 in decimal, < code > 02< / code > means 2 decimal places, so we shift point (< code > .< / code > ) 2 places left and get 1.71. Mathematically we can shift a point (< code > .< / code > ) by multiplying 10 with some power (in our case exponent). But to shift left we need to first negate the exponent so the point (< code > .< / code > ) shifts left (not right).< / p >
< p > So the formula is< / p >
< span class = "katex-display" > < span class = "katex" > < span class = "katex-mathml" > < math xmlns = "http://www.w3.org/1998/Math/MathML" display = "block" > < semantics > < mrow > < mi > m< / mi > < mi > a< / mi > < mi > n< / mi > < mi > t< / mi > < mi > i< / mi > < mi > s< / mi > < mi > s< / mi > < mi > a< / mi > < mo > ⋅< / mo > < msup > < mn > 10< / mn > < mrow > < mo > − < / mo > < mi > e< / mi > < mi > x< / mi > < mi > p< / mi > < mi > o< / mi > < mi > n< / mi > < mi > e< / mi > < mi > n< / mi > < mi > t< / mi > < / mrow > < / msup > < / mrow > < annotation encoding = "application/x-tex" >
mantissa \cdot 10^{-exponent}
< / annotation > < / semantics > < / math > < / span > < span class = "katex-html" aria-hidden = "true" > < span class = "base" > < span class = "strut" style = "height:0.6595em;" > < / span > < span class = "mord mathnormal" > man< / span > < span class = "mord mathnormal" > t< / span > < span class = "mord mathnormal" > i< / span > < span class = "mord mathnormal" > ss< / span > < span class = "mord mathnormal" > a< / span > < span class = "mspace" style = "margin-right:0.2222em;" > < / span > < span class = "mbin" > ⋅< / span > < span class = "mspace" style = "margin-right:0.2222em;" > < / span > < / span > < span class = "base" > < span class = "strut" style = "height:0.8436em;" > < / span > < span class = "mord" > 1< / span > < span class = "mord" > < span class = "mord" > 0< / span > < span class = "msupsub" > < span class = "vlist-t" > < span class = "vlist-r" > < span class = "vlist" style = "height:0.8436em;" > < span style = "top:-3.113em;margin-right:0.05em;" > < span class = "pstrut" style = "height:2.7em;" > < / span > < span class = "sizing reset-size6 size3 mtight" > < span class = "mord mtight" > < span class = "mord mtight" > − < / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > x< / span > < span class = "mord mathnormal mtight" > p< / span > < span class = "mord mathnormal mtight" > o< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > t< / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < p > Okay, we are done with theory, but how can we implement it in our code.< / p >
< p > First of all we need somehow to split our < code > numberString< / code > by < code > " s" < / code > . To do that we need to get the index at which < code > " s" < / code > in placed. To do that we can use < a href = "https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#indexOf-int-" target = "_blank" rel = "noopener" > < code > String.indexOf(char ch)< / code > < / a > method that returns the index of the first occurrence of the specified character (in our case < code > " s" < / code > ). Okay, then using < a href = "https://docs.oracle.com/javase/8/docs/api/java/lang/String.html#substring-int-" target = "_blank" rel = "noopener" > < code > String.substring()< / code > < / a > we can split into two parts. Here’ s what it’ s gonna look like< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > int< / span > indexOfS < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > indexOf< / span > (< span style = "color:#e6db74" > ' s' < / span > );
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > // all characters before ' s' , without including ' s' itself< / span >
< / span > < / span > < span style = "display:flex;" > < span > String mantissaHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (0, indexOfS);
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#75715e" > // all characters after ' s' , without including ' s' itself< / span >
< / span > < / span > < span style = "display:flex;" > < span > String exponentHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (indexOfS < span style = "color:#f92672" > +< / span > 1);< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > Note, that we use < code > 's'< / code > (not < code > " s" < / code > ) in < code > indexOf< / code > method. That’ s because it uses < a href = "https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html" target = "_blank" rel = "noopener" > < code > char< / code > < / a > data type as its argument, but < code > " s" < / code > is a string. So we need single quotes in order to represent < code > char< / code > .< / p > < / div >
< / div >
< / div >
< div class = "hx:overflow-x-auto hx:mt-6 hx:flex hx:flex-col hx:rounded-lg hx:border hx:py-4 hx:px-4 hx:border-gray-200 hx:contrast-more:border-current hx:contrast-more:dark:border-current hx:border-blue-200 hx:bg-blue-100 hx:text-blue-900 hx:dark:border-blue-200/30 hx:dark:bg-blue-900/30 hx:dark:text-blue-200" >
< p class = "hx:flex hx:items-center hx:font-medium" > < svg height = 16px class = "hx:inline-block hx:align-middle hx:mr-2" xmlns = "http://www.w3.org/2000/svg" fill = "none" viewBox = "0 0 24 24" stroke-width = "2" stroke = "currentColor" aria-hidden = "true" > < path stroke-linecap = "round" stroke-linejoin = "round" d = "M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" / > < / svg > Note< / p >
< div class = "hx:w-full hx:min-w-0 hx:leading-7" >
< div class = "hx:mt-6 hx:leading-7 hx:first:mt-0" > < p > When extracting exponent we can use only one argument (< code > indexOfS + 1< / code > ), because it will automatically go to the end of the string itself.< / p > < / div >
< / div >
< / div >
< p > Okay, now that we have < code > mantissaHexString< / code > and < code > exponentHexString< / code > we just need to convert them into decimal. That we know how to do using < code > BigInteger< / code > with base specifier.< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > BigInteger mantissa < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(mantissaHexString, 16);
< / span > < / span > < span style = "display:flex;" > < span > BigInteger exponent < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(exponentHexString, 16);< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > Okay, one thing left is to use the formula that we got< / p >
< span class = "katex-display" > < span class = "katex" > < span class = "katex-mathml" > < math xmlns = "http://www.w3.org/1998/Math/MathML" display = "block" > < semantics > < mrow > < mi > m< / mi > < mi > a< / mi > < mi > n< / mi > < mi > t< / mi > < mi > i< / mi > < mi > s< / mi > < mi > s< / mi > < mi > a< / mi > < mo > ⋅< / mo > < msup > < mn > 10< / mn > < mrow > < mo > − < / mo > < mi > e< / mi > < mi > x< / mi > < mi > p< / mi > < mi > o< / mi > < mi > n< / mi > < mi > e< / mi > < mi > n< / mi > < mi > t< / mi > < / mrow > < / msup > < / mrow > < annotation encoding = "application/x-tex" >
mantissa \cdot 10^{-exponent}
< / annotation > < / semantics > < / math > < / span > < span class = "katex-html" aria-hidden = "true" > < span class = "base" > < span class = "strut" style = "height:0.6595em;" > < / span > < span class = "mord mathnormal" > man< / span > < span class = "mord mathnormal" > t< / span > < span class = "mord mathnormal" > i< / span > < span class = "mord mathnormal" > ss< / span > < span class = "mord mathnormal" > a< / span > < span class = "mspace" style = "margin-right:0.2222em;" > < / span > < span class = "mbin" > ⋅< / span > < span class = "mspace" style = "margin-right:0.2222em;" > < / span > < / span > < span class = "base" > < span class = "strut" style = "height:0.8436em;" > < / span > < span class = "mord" > 1< / span > < span class = "mord" > < span class = "mord" > 0< / span > < span class = "msupsub" > < span class = "vlist-t" > < span class = "vlist-r" > < span class = "vlist" style = "height:0.8436em;" > < span style = "top:-3.113em;margin-right:0.05em;" > < span class = "pstrut" style = "height:2.7em;" > < / span > < span class = "sizing reset-size6 size3 mtight" > < span class = "mord mtight" > < span class = "mord mtight" > − < / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > x< / span > < span class = "mord mathnormal mtight" > p< / span > < span class = "mord mathnormal mtight" > o< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > t< / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < p > I will write the solution first and explain it right after< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(mantissa).< span style = "color:#a6e22e" > scaleByPowerOfTen< / span > (exponent.< span style = "color:#a6e22e" > negate< / span > ().< span style = "color:#a6e22e" > intValueExact< / span > ());< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > Here we are using < a href = "https://docs.oracle.com/javase/8/docs/api/java/math/BigDecimal.html#scaleByPowerOfTen-int-" target = "_blank" rel = "noopener" > < code > BigDecimal.scaleByPowerOfTen(int n)< / code > < / a > method to basically multiply by < span class = "katex" > < span class = "katex-mathml" > < math xmlns = "http://www.w3.org/1998/Math/MathML" > < semantics > < mrow > < msup > < mn > 10< / mn > < mrow > < mo > − < / mo > < mi > e< / mi > < mi > x< / mi > < mi > p< / mi > < mi > o< / mi > < mi > n< / mi > < mi > e< / mi > < mi > n< / mi > < mi > t< / mi > < / mrow > < / msup > < / mrow > < annotation encoding = "application/x-tex" > 10^{-exponent}< / annotation > < / semantics > < / math > < / span > < span class = "katex-html" aria-hidden = "true" > < span class = "base" > < span class = "strut" style = "height:0.7936em;" > < / span > < span class = "mord" > 1< / span > < span class = "mord" > < span class = "mord" > 0< / span > < span class = "msupsub" > < span class = "vlist-t" > < span class = "vlist-r" > < span class = "vlist" style = "height:0.7936em;" > < span style = "top:-3.063em;margin-right:0.05em;" > < span class = "pstrut" style = "height:2.7em;" > < / span > < span class = "sizing reset-size6 size3 mtight" > < span class = "mord mtight" > < span class = "mord mtight" > − < / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > x< / span > < span class = "mord mathnormal mtight" > p< / span > < span class = "mord mathnormal mtight" > o< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > e< / span > < span class = "mord mathnormal mtight" > n< / span > < span class = "mord mathnormal mtight" > t< / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > < / span > . Then we use < a href = "https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#negate--" target = "_blank" rel = "noopener" > < code > BigInteger.negate()< / code > < / a > to basically multiply by -1. And finally we use < a href = "https://docs.oracle.com/javase/8/docs/api/java/math/BigInteger.html#intValueExact--" target = "_blank" rel = "noopener" > < code > BigInteger.intValueExact()< / code > < / a > to get the integer value. We do that because < code > scaleByPowerOfTen< / code > method recieves integer argument (not < code > BigInteger< / code > ).< / p >
< p > So our method will look like this< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > BigDecimal < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > number.< span style = "color:#a6e22e" > isEmpty< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > String numberString < span style = "color:#f92672" > =< / span > number.< span style = "color:#a6e22e" > toString< / span > ().< span style = "color:#a6e22e" > toLowerCase< / span > ();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0x" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > numberString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (2);
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > contains< / span > (< span style = "color:#e6db74" > " s" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > int< / span > indexOfS < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > indexOf< / span > (< span style = "color:#e6db74" > ' s' < / span > );
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > String mantissaHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (0, indexOfS);
< / span > < / span > < span style = "display:flex;" > < span > String exponentHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (indexOfS < span style = "color:#f92672" > +< / span > 1);
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > BigInteger mantissa < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(mantissaHexString, 16);
< / span > < / span > < span style = "display:flex;" > < span > BigInteger exponent < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(exponentHexString, 16);
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(mantissa).< span style = "color:#a6e22e" > scaleByPowerOfTen< / span > (exponent.< span style = "color:#a6e22e" > negate< / span > ().< span style = "color:#a6e22e" > intValueExact< / span > ());
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(< span style = "color:#66d9ef" > new< / span > BigInteger(numberString, 16));
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > BigDecimal.< span style = "color:#a6e22e" > ZERO< / span > ;
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > Okay, now let’ s change < code > main< / code > method accordingly. Let’ s take < code > main< / code > method from < code > SumBigIntegerOctal< / code > modification. Here’ s what it looks like now< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > public< / span > < span style = "color:#66d9ef" > static< / span > < span style = "color:#66d9ef" > void< / span > < span style = "color:#a6e22e" > main< / span > (String< span style = "color:#f92672" > []< / span > args) {
< / span > < / span > < span style = "display:flex;" > < span > BigInteger sum < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(< span style = "color:#e6db74" > " 0" < / span > );
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > for< / span > (String argument : args) {
< / span > < / span > < span style = "display:flex;" > < span > StringBuilder number < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > StringBuilder();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > for< / span > (< span style = "color:#66d9ef" > char< / span > c : argument.< span style = "color:#a6e22e" > toCharArray< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > Character.< span style = "color:#a6e22e" > isWhitespace< / span > (c)) {
< / span > < / span > < span style = "display:flex;" > < span > number.< span style = "color:#a6e22e" > append< / span > (c);
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > sum < span style = "color:#f92672" > =< / span > sum.< span style = "color:#a6e22e" > add< / span > (parseNumber(number));
< / span > < / span > < span style = "display:flex;" > < span > number < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > StringBuilder();
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > sum < span style = "color:#f92672" > =< / span > sum.< span style = "color:#a6e22e" > add< / span > (parseNumber(number));
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > System.< span style = "color:#a6e22e" > out< / span > .< span style = "color:#a6e22e" > println< / span > (sum);
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > All we need to do is to replace the sum type from < code > BigInteger< / code > to < code > BigDecimal< / code > . So full code will look like this< / p >
< div class = "hextra-code-block hx:relative hx:mt-6 hx:first:mt-0 hx:group/code" >
< div > < div class = "highlight" > < pre tabindex = "0" style = "color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;" > < code class = "language-java" data-lang = "java" > < span style = "display:flex;" > < span > < span style = "color:#75715e" > // SumBigDecimalHex.java< / span >
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#f92672" > import< / span > java.math.BigDecimal;
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#f92672" > import< / span > java.math.BigInteger;
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > public< / span > < span style = "color:#66d9ef" > class< / span > < span style = "color:#a6e22e" > SumBigDecimalHex< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > public< / span > < span style = "color:#66d9ef" > static< / span > < span style = "color:#66d9ef" > void< / span > < span style = "color:#a6e22e" > main< / span > (String< span style = "color:#f92672" > []< / span > args) {
< / span > < / span > < span style = "display:flex;" > < span > BigDecimal sum < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(< span style = "color:#e6db74" > " 0" < / span > );
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > for< / span > (String argument : args) {
< / span > < / span > < span style = "display:flex;" > < span > StringBuilder number < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > StringBuilder();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > for< / span > (< span style = "color:#66d9ef" > char< / span > c : argument.< span style = "color:#a6e22e" > toCharArray< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > Character.< span style = "color:#a6e22e" > isWhitespace< / span > (c)) {
< / span > < / span > < span style = "display:flex;" > < span > number.< span style = "color:#a6e22e" > append< / span > (c);
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > sum < span style = "color:#f92672" > =< / span > sum.< span style = "color:#a6e22e" > add< / span > (parseNumber(number));
< / span > < / span > < span style = "display:flex;" > < span > number < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > StringBuilder();
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > sum < span style = "color:#f92672" > =< / span > sum.< span style = "color:#a6e22e" > add< / span > (parseNumber(number));
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > System.< span style = "color:#a6e22e" > out< / span > .< span style = "color:#a6e22e" > println< / span > (sum);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > static< / span > BigDecimal < span style = "color:#a6e22e" > parseNumber< / span > (StringBuilder number) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (< span style = "color:#f92672" > !< / span > number.< span style = "color:#a6e22e" > isEmpty< / span > ()) {
< / span > < / span > < span style = "display:flex;" > < span > String numberString < span style = "color:#f92672" > =< / span > number.< span style = "color:#a6e22e" > toString< / span > ().< span style = "color:#a6e22e" > toLowerCase< / span > ();
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > startsWith< / span > (< span style = "color:#e6db74" > " 0x" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > numberString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (2);
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > if< / span > (numberString.< span style = "color:#a6e22e" > contains< / span > (< span style = "color:#e6db74" > " s" < / span > )) {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > int< / span > indexOfS < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > indexOf< / span > (< span style = "color:#e6db74" > ' s' < / span > );
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > String mantissaHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (0, indexOfS);
< / span > < / span > < span style = "display:flex;" > < span > String exponentHexString < span style = "color:#f92672" > =< / span > numberString.< span style = "color:#a6e22e" > substring< / span > (indexOfS < span style = "color:#f92672" > +< / span > 1);
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > BigInteger mantissa < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(mantissaHexString, 16);
< / span > < / span > < span style = "display:flex;" > < span > BigInteger exponent < span style = "color:#f92672" > =< / span > < span style = "color:#66d9ef" > new< / span > BigInteger(exponentHexString, 16);
< / span > < / span > < span style = "display:flex;" > < span >
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(mantissa).< span style = "color:#a6e22e" > scaleByPowerOfTen< / span > (exponent.< span style = "color:#a6e22e" > negate< / span > ().< span style = "color:#a6e22e" > intValueExact< / span > ());
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(< span style = "color:#66d9ef" > new< / span > BigInteger(numberString, 16));
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > < span style = "color:#66d9ef" > new< / span > BigDecimal(numberString);
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > } < span style = "color:#66d9ef" > else< / span > {
< / span > < / span > < span style = "display:flex;" > < span > < span style = "color:#66d9ef" > return< / span > BigDecimal.< span style = "color:#a6e22e" > ZERO< / span > ;
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }
< / span > < / span > < span style = "display:flex;" > < span > }< / span > < / span > < / code > < / pre > < / div > < / div > < div class = "hextra-code-copy-btn-container hx:opacity-0 hx:transition hx:group-hover/code:opacity-100 hx:flex hx:gap-1 hx:absolute hx:m-[11px] hx:right-0 hx:top-0" >
< button
class = "hextra-code-copy-btn hx:group/copybtn hx:cursor-pointer hx:transition-all hx:active:opacity-50 hx:bg-primary-700/5 hx:border hx:border-black/5 hx:text-gray-600 hx:hover:text-gray-900 hx:rounded-md hx:p-1.5 hx:dark:bg-primary-300/10 hx:dark:border-white/10 hx:dark:text-gray-400 hx:dark:hover:text-gray-50"
title = "Copy code"
>
< div class = "hextra-copy-icon hx:group-[.copied]/copybtn:hidden hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< div class = "hextra-success-icon hx:hidden hx:group-[.copied]/copybtn:block hx:pointer-events-none hx:h-4 hx:w-4" > < / div >
< / button >
< / div >
< / div >
< p > This code works correctly and passes all the tests!< / p >
< / div >
< div class = "hx:mt-16" > < / div >
< div class = "hx:mt-16" > < / div >
< / main >
< / article >
< / div >
< script defer src = "/js/main.js" integrity = "" > < / script >
< script defer src = "/js/flexsearch.9f5b5908f93ae86f1ecd4b043b799f580c2d1654e703dd9357d568ac41b2547a.js" integrity = "sha256-n1tZCPk66G8ezUsEO3mfWAwtFlTnA92TV9VorEGyVHo=" crossorigin = "anonymous" > < / script >
< script defer src = "/en.search.js" integrity = "" > < / script >
< / body >
< / html >