kylomas Posted January 3, 2011 Share Posted January 3, 2011 (edited) Happy 2011, Does anyone know how to display the binary representation of a byte? e.g. int=8 might be "0000 0000 0000 1000" (assuming 2 byte int) Thanks, kylomas Edited January 3, 2011 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 3, 2011 Moderators Share Posted January 3, 2011 kylomas,A quick search of the forum (the Search facility is at top right of the page ) found this. It might be useful. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Mat Posted January 3, 2011 Share Posted January 3, 2011 These are always my preferred functions. None of the others on the forums really compare there is also the reverse here: I wish WBD was here more often. AutoIt Project Listing Link to comment Share on other sites More sharing options...
KaFu Posted January 3, 2011 Share Posted January 3, 2011 Just out of curiosity, do I get this right? $sString = "The quick brown fox jumps over the lazy dog" $iStringLength = StringLen($sString) For $i = 1 To $iStringLength $sChar = StringMid($sString, $i, 1) ConsoleWrite($sChar & @tab) $sBin = _ToBase(Dec(StringReplace(StringToBinary($sChar), "0x", "")), 2, 8) ConsoleWrite($sBin & @crlf) Next ; by WideBoyDixon ; http://www.autoitscript.com/forum/topic/93742-converting-decimal-numbers-to-another-base/page__view__findpost__p__673358 Func _ToBase($iNumber, $iBase, $iPad = 1) Local $sRet = "", $iDigit Do $iDigit = Mod($iNumber, $iBase) If $iDigit < 10 Then $sRet = String($iDigit) & $sRet Else $sRet = Chr(55 + $iDigit) & $sRet EndIf $iNumber = Int($iNumber / $iBase) Until ($iNumber = 0) And (StringLen($sRet) >= $iPad) Return $sRet EndFunc ;==>_ToBase OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
kylomas Posted January 3, 2011 Author Share Posted January 3, 2011 Melba23, Thanks, could'nt find the right search terms to pop these results... kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Mat Posted January 3, 2011 Share Posted January 3, 2011 Just out of curiosity, do I get this right? I think this is what you intended: $sString = "The quick brown fox jumps over the lazy dog" $iStringLength = StringLen($sString) For $i = 1 To $iStringLength $sChar = StringMid($sString, $i, 1) ConsoleWrite($sChar & @TAB & Asc($sChar) & @TAB) $sBin = _ToBase(Asc($sChar), 2, 8) ConsoleWrite($sBin & @crlf) Next ; by WideBoyDixon ; http://www.autoitscript.com/forum/topic/...her-base/page__view__findpost_ Func _ToBase($iNumber, $iBase, $iPad = 1) Local $sRet = "", $iDigit Do $iDigit = Mod($iNumber, $iBase) If $iDigit < 10 Then $sRet = String($iDigit) & $sRet Else $sRet = Chr(55 + $iDigit) & $sRet EndIf $iNumber = Int($iNumber / $iBase) Until ($iNumber = 0) And (StringLen($sRet) >= $iPad) Return $sRet EndFunc ;==>_ToBase To convert AutoIt's binary representation to binary bits there is this function: of course I'm trying to guess what you were trying to do, I may be wrong. AutoIt Project Listing Link to comment Share on other sites More sharing options...
KaFu Posted January 3, 2011 Share Posted January 3, 2011 (edited) All functions deliver the same result ... hmmmm, how about unicode characters? E.g. feeding a Russian Л to the function results in a console output like "? 00111111", П the same "? 00111111". expandcollapse popup$sString = "The quick brown fox jumps over the lazy dog" $iStringLength = StringLen($sString) For $i = 1 To $iStringLength $sChar = StringMid($sString, $i, 1) ConsoleWrite($sChar & @tab) $sBin = _ToBase(Dec(StringReplace(StringToBinary($sChar), "0x", "")), 2, 8) ConsoleWrite($sBin & @tab) $sBin2 = BinaryToBits(StringToBinary($sChar)) ConsoleWrite($sBin2 & @crlf) Next $iStringLength = StringLen($sString) For $i = 1 To $iStringLength $sChar = StringMid($sString, $i, 1) ConsoleWrite($sChar & @TAB) $sBin = _ToBase(Asc($sChar), 2, 8) ConsoleWrite($sBin & @crlf) Next ; by WideBoyDixon ; http://www.autoitscript.com/forum/topic/93742-converting-decimal-numbers-to-another-base/page__view__findpost__p__673358 Func _ToBase($iNumber, $iBase, $iPad = 1) Local $sRet = "", $iDigit Do $iDigit = Mod($iNumber, $iBase) If $iDigit < 10 Then $sRet = String($iDigit) & $sRet Else $sRet = Chr(55 + $iDigit) & $sRet EndIf $iNumber = Int($iNumber / $iBase) Until ($iNumber = 0) And (StringLen($sRet) >= $iPad) Return $sRet EndFunc ;==>_ToBase ; by SkinnyWhiteGuy ; http://www.autoitscript.com/forum/topic/93345-binary-digits-stuff/page__p__670985#entry670985 Func BinaryToBits($bin) Local $output For $i = 1 To BinaryLen($bin) For $j = 7 To 0 Step -1 $output &= BitAND(BitShift(BinaryMid($bin, $i, 1), $j), 1) Next Next Return $output EndFunc Edited January 3, 2011 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
kylomas Posted January 3, 2011 Author Share Posted January 3, 2011 Mat, Precicely what I was looking for, thanks. Just as an aside, I appreciate the patients all members of this forum have shown. I am an old MVS (mainframe operating system) guy trying to figure out this Windows thing. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Mat Posted January 3, 2011 Share Posted January 3, 2011 All functions deliver the same result ... hmmmm, how about unicode characters? E.g. feeding a Russian Л to the function results in a console output like "? 00111111", П the same "? 00111111". I can't seem to get SciTE to let me use russian characters... So I copy + pasted this: > Привет мир! < (Got from google translate). It recognizes that the characters are different and seems to give the right results... Unfortunately I don't know russian, so can't tell you if it's doing what it should. Only real changes are that it uses AscW and pads it to 16 bits. Ascii characters still give the same results though $sString = ClipGet() $iStringLength = StringLen($sString) For $i = 1 To $iStringLength $sChar = StringMid($sString, $i, 1) ConsoleWrite($sChar & @TAB & AscW($sChar) & @TAB) $sBin = _ToBase(AscW($sChar), 2, 16) ConsoleWrite($sBin & @crlf) Next ; by WideBoyDixon ; http://www.autoitscript.com/forum/topic/...her-base/page__view__findpost_ Func _ToBase($iNumber, $iBase, $iPad = 1) Local $sRet = "", $iDigit Do $iDigit = Mod($iNumber, $iBase) If $iDigit < 10 Then $sRet = String($iDigit) & $sRet Else $sRet = Chr(55 + $iDigit) & $sRet EndIf $iNumber = Int($iNumber / $iBase) Until ($iNumber = 0) And (StringLen($sRet) >= $iPad) Return $sRet EndFunc ;==>_ToBase AutoIt Project Listing Link to comment Share on other sites More sharing options...
KaFu Posted January 3, 2011 Share Posted January 3, 2011 (edited) AscW() did the trick . Here's a good source for digging deeper.Edit: , the author called the article "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)" Edited January 3, 2011 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Mat Posted January 5, 2011 Share Posted January 5, 2011 I read it a while back, I think it was linked to from here by someone else a while ago. The author is right of course AutoIt Project Listing Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now