is this legal: int X=1010+0x10+0101

# Thread: is this legal: int X=1010+0x10+0101

1. ElinM Guest

## is this legal: int X=1010+0x10+0101

is this legal: int X=1010 + 0x10 + 0101<BR>if yes, what is value of X? why?<BR><BR>Thanks for your help.<BR>Elin<BR><BR><BR>

2. JH
Senior Member
Join Date
Dec 1969
Posts
101

## RE: is this legal: int X=1010+0x10+0101

One might wonder what language that is supposed to represent.<BR><BR>I&#039ll take a stab at it and look at it through the lenses of JavaScript.<BR><BR>var x = 1010 + 0x10 + 0101;<BR><BR>After the declaration of "x" as a variable, you&#039re assigning the sum of three numeric values to it; one decimal, one hexadecimal, and one octal.<BR><BR>0x10 as base 16 is equivalent to 16 in decimal, and<BR>0101 as base 8 is equivalent to 65 in decimal.<BR><BR>So, x = 1010 + 16 + 65<BR>or, x = 1091<BR><BR>

3. ElinM Guest

## thanks, one more fundamental question

How do you convert hexadecimal to decimal and octal to decimal?

4. ElinM Guest

## never mind. I have got the answer. thanks!

:)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•