100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Test (elaborations) Computer programming

Rating
-
Sold
-
Pages
1
Grade
A+
Uploaded on
22-04-2025
Written in
2024/2025

Perfect for examination preparation , it includes multiple questions for revision.

Institution
Senior / 12th Grade
Course
Computer programming








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
Senior / 12th grade
Course
Computer programming
School year
3

Document information

Uploaded on
April 22, 2025
Number of pages
1
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

Number Systems Conversions using recursion

// Convert Decimal to Binary
public static int D2B(int n) {
if (n == 0) {
return 0;
}
return D2B(n / 2) * 10 + (n % 2);
}
-----------------------------------------------+
// Convert Binary to Decimal
public static int B2D(int b) {
if (b == 0) {
return 0;
}
return (b % 10) + 2 * B2D(b / 10);
}
-------------------------------------------------
// Convert Decimal to Octal
public static int D2O(int n) {
if (n == 0) {
return 0;
}
return D2O(n / 8) * 10 + (n % 8);
}
-------------------------------------------------
// Convert Octal to Decimal
public static int O2D(int o) {
if (o == 0) {
return 0;
}
return (o % 10) + 8 * O2D(o / 10);
}
-------------------------------------------------
// Convert Decimal to Hexadecimal (returns a String)
public static String D2H(int n) {
if (n == 0) {
return "";
}
String hexDigits = "0123456789ABCDEF";
return D2H(n / 16) + hexDigits.charAt(n % 16);
}
-------------------------------------------------
// Convert Hexadecimal to Decimal
public static int H2D(String h) {
if (h.length() == 0) {
return 0;
}
char firstChar = h.charAt(0);
int firstDigit = (firstChar >= '0' && firstChar <= '9') ? (firstChar - '0') : (firstChar - 'A' + 10);
return firstDigit * (int) Math.pow(16, h.length() - 1) + H2D(h.substring(1));
}
$9.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
tisyaverma

Get to know the seller

Seller avatar
tisyaverma Physics wallah
View profile
Follow You need to be logged in order to follow users or courses
Sold
0
Member since
8 months
Number of followers
0
Documents
13
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions