Converting 3 cells to binary and grouping them into 8-bits then converting each 8-bit group back to decimal

xjpx

New Member
Joined
Jan 3, 2022
Messages
25
Office Version
  1. 365
Platform
  1. Windows
Hi all, let me go straight down to the question

As per the title, I want to convert 3 decimal values to 3 separate binary and group them into 8-bits groups then converting each group back to decimal.

Steps are as follows,
1. Take the data from sheet 1 K2, L2, M2 and N2 (Eg. K2: 34801152, L2: 196879 M2: ...)
2. Convert them to 32-bit binary (Eg. K2: 00000010000100110000011000000000, L2: 00000000000000110000000100001111)
3. Group the 32-bits into 8-bits groups (Eg. K2: 00000010 00010011 00000110 00000000, L2: 00000000 00000011 00000001 00001111)
4. Convert each 8-bit group into decimal (Eg. K2: 2.19.6.0 , L2: 0.3.1.15)
5. Paste these values into sheet 2 cells A2, B2, C2 and D2 respectively.

The end product should look like the image below in sheet 2.

Thanks all! If you require any more information please let me know
1642649946472.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
in 4 steps (can be done in an UDF)
xxxxxxxx.xlsx
ABCD
1consecutive divide by 256modus 256
23480115234.801.1520
32.19.6.0135.9426
425653119
522
602.19.6.0
Blad1
Cell Formulas
RangeFormula
C2C2=+A2
D2:D5D2=MOD(C2+1,$A$4)-1
C3:C6C3=+TRUNC(C2/$A$4)
D6D6=TEXTJOIN(".",1,D5,D4,D3,D2)
 
Upvote 0
VBA Code:
Function Bit8(getal)
     Application.Volatile

     If getal < 0 Then Exit Function
     Do
          rest = ((getal + 1) Mod 256) - 1
          Bit8 = "." & rest & Bit8
          getal = Int(getal / 256)
     Loop While getal > 0
     Bit8 = Mid(Bit8, 2)

End Function
 
Upvote 0
Upvote 0
Another option
+Fluff 1.xlsm
ABCKL
1
22.19.6.00.3.1.1534801152196879
Main
Cell Formulas
RangeFormula
A2:B2A2=TEXTJOIN(".",,BIN2DEC(MID(BASE(K2,2,32),SEQUENCE(,4,,8),8)))
 
Upvote 0
Another option
+Fluff 1.xlsm
ABCKL
1
22.19.6.00.3.1.1534801152196879
Main
Cell Formulas
RangeFormula
A2:B2A2=TEXTJOIN(".",,BIN2DEC(MID(BASE(K2,2,32),SEQUENCE(,4,,8),8)))
This is great but I have to use the function ='Sheet 1'!K2*1 to extract the data from Sheet1 to Sheet 2. Other than that this works well.
 
Upvote 0
VBA Code:
Function Bit(getal As Long)
     Application.Volatile
     If getal < 0 Then Exit Function
     Do
          rest = ((getal + 1) Mod 256) - 1
          Bit = "." & rest & Bit
          getal = Int(getal / 256)
     Loop While getal > 0
     Bit = Mid(Bit, 2)

End Function
Cell Formulas
RangeFormula
H1H1=POWER(2,31)
J1:M1J1=RANDBETWEEN(1,$H$1)
J2:M2J2=BIT(J1)
This is great! I don't really get why you added a power and randbetween function. I used the VBA code and use =Bit(cell) function and it works.
 
Upvote 0
that was only for demonstration, to pick every time 4 new variables (the randbetween-formula).
2^31 = approx 2,150,000,000 = maximum number excel allows
 
Upvote 0
This is great but I have to use the function ='Sheet 1'!K2*1 to extract the data from Sheet1 to Sheet 2.
You never mentioned that the sells were on different sheets. ;)

Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,558
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top