programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# Question from appliedreasoning mock exam

Ranch Hand
Posts: 186
• • Number of slices to send:
Optional 'thank-you' note:
• • What is the result of the following frament of code:
int a=0x67;
int b=0xBD;
a^b
a.0xFF
b.0xDA
c.0x25
d.0xAA

Ranch Hand
Posts: 18944
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by sdev:
What is the result of the following frament of code:
int a=0x67;
int b=0xBD;
a^b
a.0xFF
b.0xDA
c.0x25
d.0xAA

1) Get binary equivalent of a and b i.e
0110 0111 (a)
1011 1101 (b)
2) Now a ^ b gives 1101 1010.Its equivalent hexadecimal
representation is 0xDA.

Greenhorn
Posts: 29
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by sdev:
What is the result of the following frament of code:
int a=0x67;
int b=0xBD;
a^b
a.0xFF
b.0xDA
c.0x25
d.0xAA

0x67 is 01100111 and 0xBD is 11011010
01100111
^
10111101
____________
11011010 which is 0xDA.
Kai

Greenhorn
Posts: 6
• • Number of slices to send:
Optional 'thank-you' note:
• • Hi,
can anyone explain how binary of 0X67 = 0110 0111
& 0xBD = 1011 1101
Thx.

Sheriff Posts: 5782
• • Number of slices to send:
Optional 'thank-you' note:
• • Hex to binary conversion is very easy to remember. In your first step sepearates the digits in the hex number. In your second step, conver each hex digit to binary.
Now lets look at your question.
0X67
Step 1 after separating the digits, we get - 6,7
Step 2 Convert each to binary
ie., 6 = 0110
7 = 0111
Putting it together, we get 0X67 = 0110 0111
Follow the same rules for 0xBD and you will get to the answer.
Ajith

Raj Gupta
Greenhorn
Posts: 6
• • Number of slices to send:
Optional 'thank-you' note:
• • Kai,
can u please tell me how do u getthe value for 0xBD i.e 11011010
Thx

Raj Gupta
Greenhorn
Posts: 6
• • Number of slices to send:
Optional 'thank-you' note:
• • Ajith,
d- decimal ; h-hexa ; o-octal
d h o
10x1 01
20x2 02
3 0x3 03
4 0x4 04
50x5 05
60x6 06
70x7 07
8 0x8 010
9 0x9 011
10 0xA 012
11 0xB 013
12 0xC 014
13 0xD 015
14 0xE 016
150xF 017
Here for 0XBD I assume I should find the binary value for B & D separately...i.e 0XB = 11 & OxD = 13...
binary value for 11 = 1011 & 13 = 1101.....Is this correct....?
Is this the way to convert ?
Thx

Ranch Hand
Posts: 36
• • Number of slices to send:
Optional 'thank-you' note:
• • Ajith said said 0xBD = 1011 1101 which is:
1011 = (1 * (2^3)) + (0 * (2^2)) + (1* (2^1)) + (1*(2^0)) = 11 (base 10) which is B hex
1101 = (1 * (2^3)) + (1 * (2^2)) + (0* (2^1)) + (1*(2^0)) = 13 (base 10) which is D hex

Ajith Kallambella
Sheriff Posts: 5782
• • Number of slices to send:
Optional 'thank-you' note:
• • Yes, you got it right. But remember, use this rule only for HEX to binary conversion. Not octal to binary!!
If you are running Windows, then you can use the calculator program under accessories to verify your results. If you switch to Scientific mode, you can convert from one base to another.
Ajith
[This message has been edited by Ajith Kallambella (edited August 16, 2000).]

Raj Gupta
Greenhorn
Posts: 6
• • Number of slices to send:
Optional 'thank-you' note:
• • Can anyone tell how 0xBD = 1011 1101 ?

Raj Gupta
Greenhorn
Posts: 6
• • Number of slices to send:
Optional 'thank-you' note:
• • Can anyone tell how 0xBD = 1011 1101 ?

daryl olson
Ranch Hand
Posts: 36
• • Number of slices to send:
Optional 'thank-you' note:
• • Is this what you need to know?
Hex numbers go from 0 to F and are mapped to decinal # as follows:
Dec -> Hex
0 0
1 1
2 2
...and so on until you reach 10
10 A
11 B
12 C
13 D
14 E
15 F

Anonymous
Ranch Hand
Posts: 18944
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by ggg:
Can anyone tell how 0xBD = 1011 1101 ?

Binary table is used:
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
A 1010
B 1011
C 1100
D 1101
E 1110
F 1111
Now, get this table if you each time push "1" from the right
- 0 and 1 leave 1
- 1 and 1 leave 0 AND 1 moves to the next column where you apply the same logic. Post if you need a bit more help. pie. tiny ad: Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton