User Name Remember Me? Password

 Computer Science Computer Science Forum

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

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.
Attached Images 2018-04-08_14-01-15.jpg (22.7 KB, 8 views) April 8th, 2018, 10:46 AM   #2
Senior Member

Joined: Sep 2015
From: USA

Posts: 2,585
Thanks: 1430

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:
 I am told that the bit numbers start with 1 and ends with 128 from left to right.
I have no idea what this means. April 9th, 2018, 12:08 AM #3 Senior Member   Joined: Apr 2014 From: UK Posts: 965 Thanks: 342 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 8-4-2-1) 7 binary => 0111 XOR => 0011 Add the number of bits => 2 Thanks from Tricia April 10th, 2018, 04:42 PM #4 Newbie   Joined: Jan 2018 From: Toronto Posts: 12 Thanks: 0 Greatly appreciated - Just a follow-up question. Not clear on what is meant by note that the binary weighting for each digit is 8-4-2-1 - 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: 93 Thanks: 48 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); } } Thanks from Tricia April 10th, 2018, 11:35 PM   #6
Senior Member

Joined: Apr 2014
From: UK

Posts: 965
Thanks: 342

Quote:
 Originally Posted by Tricia Greatly appreciated - Just a follow-up question. Not clear on what is meant by note that the binary weighting for each digit is 8-4-2-1 - Is this referencing a binary chart?
Not a chart exactly, Take the Hex digit 'F', we know that is '1111' in binary.
The left-most 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.

Quote:
 Originally Posted by Tricia 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.
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 Show Printable Version Email this Page Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode Similar Threads Thread Thread Starter Forum Replies Last Post marenello99 Elementary Math 6 February 28th, 2016 11:26 PM go2255 Linear Algebra 1 October 28th, 2013 09:43 AM Flupps Algebra 2 September 12th, 2013 08:49 PM sivela Physics 3 January 29th, 2012 12:06 PM zgonda Algebra 2 August 18th, 2010 06:56 AM

 Contact - Home - Forums - Cryptocurrency Forum - Top      