Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6560 |

@blackshadows | 6400 |

@mb1973 | 5777 |

@Quandray | 5275 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5074 |

@kirtidee18 | 4408 |

@sanjay05 | 3762 |

@mantu_singh | 3666 |

@gfgaccount | 3605 |

@marius_valentin_dragoi | 3525 |

Complete Leaderboard | |

Handle | Score |

@anish5256 | 991 |

@vimleshpratapsingh321 | 980 |

@skj7 | 953 |

@kanewilliamson123 | 894 |

@pradeeppatidar1999 | 868 |

@akhileshkumar562002 | 862 |

@wallflowe101 | 826 |

@pd420786 | 813 |

@infilooop | 800 |

@bunnybug320 | 796 |

@nikhilkushwah280 | 796 |

Complete Leaderboard |

Given a number N, swap the two nibbles in it and find the resulting number.

**Example 1:**

Input:N = 100Output:70Explanation:100 in binary is 01100100, two nibbles are (0110) and (0100) If we swap the two nibbles, we get 01000110 which is 70 in decimal

**Example 2:**

Input:N = 129Output:24Explanation:129 in binary is 10000001, two nibbles are (1000) and (0001) If we swap the two nibbles, we get 00011000 which is 24 in decimal

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **swapNibbles()** which takes an integer **N** as input parameters and returns an integer after swapping nibbles in the binary representation of N.

**Expected Time Complexity:** O(1)

**Expected Space Complexity:** O(1)

**Constraints:**

0 ≤ N ≤ 255

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Swap two nibbles in a byte

...