
Computer Science Computer Science Forum 
 LinkBack  Thread Tools  Display Modes 
April 8th, 2018, 10:10 AM  #1 
Newbie Joined: Jan 2018 From: Toronto Posts: 12 Thanks: 0  Find Total Bit Difference
How do you determine what the bit number difference using Hexadecimal? Searching online and only finding a calculator for convert into binary or decimal. Ciphertext1 Hexadecimal  4fab160df31483063a0759055a506a7c Ciphertext2 Hexadecimal  7edbef6e5cc23adde6e2bf5b6d03fb38 I am to compare the two by calculating the bit difference. I am told that the bit numbers start with 1 and ends with 128 from left to right. Please find attached the chart that is to assist with answering the question. Kindly assist because I have no clue how to answer this question using the chart. If anyone is aware of a site that calculates this information that is also an option. Greatly appreciated! Thank you. 
April 8th, 2018, 10:46 AM  #2  
Senior Member Joined: Sep 2015 From: USA Posts: 2,091 Thanks: 1087 
It looks like you just pop your two hex numbers into that table and read out the # of bits that don't agree. Do that for each hex digit and sum up the # bits for each one. Your two numbers don't appear to be the same length though. Quote:
 
April 9th, 2018, 12:08 AM  #3 
Senior Member Joined: Apr 2014 From: UK Posts: 883 Thanks: 323 
Those hex strings are the same length (32 digits), I copy/pasted into notepad to check I would have said that the bit numbers start with 1 and end with 128 from right to left However, that's for 2 Hex digits, for a single digit it ends at 8 on the left. Note that the table is symmetrical, so it doesn't matter whose digit is the row and whose is the column. What the table is doing for you is a bitwise XOR on the hex digits then adding up the bits in the result. Let's take the first digits 4 and 7 4 binary => 0100 (note that the binary weighting for each digit is 8421) 7 binary => 0111 XOR => 0011 Add the number of bits => 2 
April 10th, 2018, 04:42 PM  #4 
Newbie Joined: Jan 2018 From: Toronto Posts: 12 Thanks: 0 
Greatly appreciated  Just a followup question. Not clear on what is meant by note that the binary weighting for each digit is 8421  Is this referencing a binary chart? I have an understanding of how to XOR using the two Ciphertext Hexadecimal and then add it to get the bits. Not clear on whether I add all the bits as a total. The homework question is to compare the two and give the Total bit difference. Please assist  Ciphertext1 Hexadecimal  4fab160df31483063a0759055a506a7c Ciphertext2 Hexadecimal  7edbef6e5cc23adde6e2bf5b6d03fb38 Hexadecimal Binary 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 Trying to search online to have an understanding, but it is creating more confusion. Thanks in advance. Last edited by Tricia; April 10th, 2018 at 05:26 PM. 
April 10th, 2018, 07:03 PM  #5 
Member Joined: Jan 2016 From: Athens, OH Posts: 89 Thanks: 47 
I assume what is expected is that you compute the bit difference between corresponding hex digits in the two strings and then add all these bit differences. It seems unreasonable to me to do this by hand. Here's a little Java class that may be instructive. I assume you know some language similar to Java; ^ is exclusive or, & is logical and. Code: public class BitDifference { int hexCharToInt(char ch) { ch = Character.toUpperCase(ch); int value; if (ch >= 'A') { value = 10 + ch  'A'; } else { value = ch  '0'; } return (value); } int bitDifferenceChars(char ch1, char ch2) { int one = hexCharToInt(ch1); int two = hexCharToInt(ch2); int bitDiff = one ^ two; int result = 0; while (bitDiff != 0) { result += (bitDiff & 1); bitDiff >>= 1; } return (result); } int totalBitDifferenceMethod(String h1, String h2) { if (h1.length() > h2.length()) { String temp = h1; h1 = h2; h2 = temp; } int i; int totalBitDifference = 0; for (i = 0; i < h1.length(); i++) { totalBitDifference += bitDifferenceChars(h1.charAt(i), h2.charAt(i)); } while (i < h2.length()) { totalBitDifference += bitDifferenceChars('0', h2.charAt(i)); i++; } return (totalBitDifference); } } 
April 10th, 2018, 11:35 PM  #6  
Senior Member Joined: Apr 2014 From: UK Posts: 883 Thanks: 323  Quote:
The leftmost bit is worth 8, the 2nd bit is worth 4, the 3rd 2 and the last bit 1, thus the binary bits have a weighting. For 8 bit values, the left most bit is worth 128. I agree with John, you add up all the bits. However, I think there is a definite point to doing this by hand at least once, it helps to gain familiarity with hex and shows that whatever solution you use, some sort of procedure is followed and it takes time. The stage is then set for the next lesson where it is explained that we don't do this by hand...  

Tags 
bit, difference, find, total 
Thread Tools  
Display Modes  

Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
difference between a percentage increase each year and total change  marenello99  Elementary Math  6  February 28th, 2016 11:26 PM 
Help!Find the total moment.  go2255  Linear Algebra  1  October 28th, 2013 09:43 AM 
How do I find the total area of a cylinder?  Flupps  Algebra  2  September 12th, 2013 08:49 PM 
Find the total capacitance  sivela  Physics  3  January 29th, 2012 12:06 PM 
find the total area  zgonda  Algebra  2  August 18th, 2010 06:56 AM 