Morthawt Posted January 17, 2015 Share Posted January 17, 2015 I am currently manually producing binary 1's and 0's and re-processing into 4bit integers. Is there some easier method without having to manually convert down to the 1's and 0's binary level first? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
BrewManNH Posted January 17, 2015 Share Posted January 17, 2015 Huh? If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
UEZ Posted January 17, 2015 Share Posted January 17, 2015 What about BitShift? $i32bit = 123456789 ;0x075BCD15 = 0111.0101.1011.1100.1101.0001.0101 ; 7 5 11 12 13 1 5 For $i = 0 To 7 ConsoleWrite(BitAND(0xF, BitShift($i32bit, 4 * $i)) & @CRLF) Next Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2015 Share Posted January 17, 2015 Huh? I'd like to see a 4 bit integer too AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 Like, take this 32 bit number: 55028615 The binary representation of it is: 00000011010001111010101110000111 Then you break it down into groupings of 4: 0000 0011 0100 0111 1010 1011 1000 0111 Then break each 4 bit block into a 4 bit number: 0 3 4 7 10 11 8 7 Is there some easier method than manually converting down and processing individual bits? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 What about BitShift? $i32bit = 123456789 ;0x075BCD15 = 0111.0101.1011.1100.1101.0001.0101 ; 7 5 11 12 13 1 5 For $i = 0 To 7 ConsoleWrite(BitAND(0xF, BitShift($i32bit, 4 * $i)) & @CRLF) Next Br, UEZ That is looking very close to what I want. I just need to process and understand what it is doing. I think that would work, in reverse ordering. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
UEZ Posted January 17, 2015 Share Posted January 17, 2015 For $i = 7 To 0 Step - 1 Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 For $i = 7 To 0 Step - 1 Br, UEZ yes I got this done already. I am just trying to decipher what the code you wrote is doing. I am not too familiar with bitwise functions. I know bitand searches to see if a particular bit is flipped or not in a given number I think. But I am quite confused right now until I understand it. If you can provide an English explanation of what the functions are doing that would help me a lot most likely. Thanks. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
UEZ Posted January 17, 2015 Share Posted January 17, 2015 (edited) The 1. step is to shift the bits of the 32 bit number 4 * $i bits to the right. This is done by the BitShift($i32bit, 4 * $i) command. To mask the result only to the last 4 bits (2^4-1 = 15) I used the BitAND() command. BitAND(0xF, the result of the bitshift) = the result. Ok? Br, UEZ Edited January 17, 2015 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 (edited) Erm... not really lol. I do not visually understand what it is doing. Plus I think BitAnd is the thing I use to check if a number has a particular binary bit flipped like finding out what options have been set on a combined number like option 1, option 2, option 4, option 8 etc. Then I can run a check to see if option 8 is part of that number. But in this situation I have no clue what bitand is doing or how the bits get shifted by the bitshift. I rarely ever deal with anything other than bitand, and in this situation my usage does not seem to fit with your usage. Edited January 17, 2015 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 I think I understand the shift, it moves to the right so each time it cycles through the last 4 digits are discarded and the 4 prior are now at the end I think. But it seems like BitAnd may have two functions. I use it to determine if a paritcular bit was flipped to create the big number presented. If the number is not 0 then it was part of creating it. But it seems adding a hex 0xF is acting as a mask? Only giving a single first 4 bit grouping? Is this correct? Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
Solution UEZ Posted January 17, 2015 Solution Share Posted January 17, 2015 (edited) Here a more detailed description:1. BitShift(123456789, 4 * 0) -> no shifting -> $result = 123456789 BitAND(0xF, 123456789) = 5 0111.0101.1011.1100.1101.0001.0101 0000.0000.0000.0000.0000.0000.1111 = 0000.0000.0000.0000.0000.0000.0101 -> = 5 2. BitShift(123456789, 4 * 1) -> shift the bits 4 times to the right -> 0000.0111.0101.1011.1100.1101.0001 = 7716049 BitAND(0xF, 7716049) = 1 0000.0111.0101.1011.1100.1101.0001 0000.0000.0000.0000.0000.0000.1111 = 0000.0000.0000.0000.0000.0000.0001 -> = 1 3. BitShift(123456789, 4 * 2) -> shift the bits 8 times to the right -> 0000.0000.0111.0101.1011.1100.1101 = 482253 BitAND(0xF, 482253) = 13 0000.0000.0111.0101.1011.1100.1101 0000.0000.0000.0000.0000.0000.1111 = 0000.0000.0000.0000.0000.0000.1101 -> = 13 ... Eg: 1101 = 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 = 8 + 4 + 0 + 1 = 13I hope it helps you to understand now. And operation on bit level: 0 and 0 = 00 and 1 = 01 and 0 = 01 and 1 = 1 Br,UEZ Edited January 17, 2015 by UEZ Morthawt and JohnOne 2 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 (edited) Here a more detailed description: 1. BitShift(123456789, 4 * 0) -> no shifting -> $result = 123456789 BitAND(0xF, 123456789) = 5 0111.0101.1011.1100.1101.0001.0101 0000.0000.0000.0000.0000.0000.FFFF = 0000.0000.0000.0000.0000.0000.0101 -> = 5 2. BitShift(123456789, 4 * 1) -> shift the bits 4 times to the right -> 0000.0111.0101.1011.1100.1101.0001 = 7716049 BitAND(0xF, 7716049) = 1 0000.0111.0101.1011.1100.1101.0001 0000.0000.0000.0000.0000.0000.FFFF = 0000.0000.0000.0000.0000.0000.0001 -> = 1 3. BitShift(123456789, 4 * 2) -> shift the bits 8 times to the right -> 0000.0000.0111.0101.1011.1100.1101 = 482253 BitAND(0xF, 482253) = 1 0000.0000.0111.0101.1011.1100.1101 0000.0000.0000.0000.0000.0000.FFFF = 0000.0000.0000.0000.0000.0000.1101 -> = 13 ... Eg: 1101 = 1*2^3 + 1*2^2 + 0*2^1 + 1*2^0 I hope it helps you to understand now. And operation on bit level: 0 and 0 = 0 0 and 1 = 0 1 and 0 = 0 1 and 1 = 1 Br, UEZ I think so. So I was right, shift is lopping bits off the end and shifting the remaining over to the right (or left if you use negative number) and I think after some experimentation and looking at your depiction that I have a better understanding of BitAnd. I think BitAnd uses the first parameter to return all the values that are in the second parameter by checking only the bits used that are represented in the first parameter. So if on the first parameter I put in 3 and a number in the right it will only return the value based on the 1 and 2 bits, so it could produce a 0, 1, 2 or 3 since those bits can only produce those numbers. So if you use 0xF for the first or even 15, it returns the value of the second number but only up to the value produced by the status of the bits that can make up that first number, in this instance being 15 maximum. Does that sound about right? Edited January 17, 2015 by Morthawt Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2015 Share Posted January 17, 2015 (edited) Excuse me for butting in UEZ, that seems just like a logic And gate in electronics, is that correct? Edited January 17, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2015 Share Posted January 17, 2015 In an Or gate it would be. 0 or 0 = 0 0 or 1 = 1 1 or 0 = 1 1 or 1 = 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
UEZ Posted January 17, 2015 Share Posted January 17, 2015 (edited) Sorry, I made a mistake by adding the FFFF. That makes no sense here! It must be 1111 (=15 or 0xF) of course!But your understanding seems to be correct.BitAnd masks the bits only. In this case you just cut off the bits from 32 to 4 because the 1st 4 bits are what you are looking for.@J1: correct it is the same as the logic AND gate in electronicsBr,UEZ Edited January 17, 2015 by UEZ JohnOne 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2015 Share Posted January 17, 2015 Cheers, my virtually non existent understanding of their use just increased tenfold. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Morthawt Posted January 17, 2015 Author Share Posted January 17, 2015 Thank you UEZ. I love being able to improve my code with just these little elegant pieces of functionality. Once you truly understand the what and why, it is so much more useful. The help file does not really explain what the bitwise functions do very well. It assumes you know what they already are and just shows examples of them being used. I think better documentation would help. I might not have needed to make a post on the forum if I understood them from the beginning. I immediately went to the bitwise section but it was all greek to me. So I did a whole thing converting to bit binary and grouping things up etc :S very CPU time consuming compared to your method. So, thanks again for help me to understand it. Free and easy Autoit scripting video tutorials (plus more videos always coming!) General video tutorials, especially correct and safe TeamSpeak permissions tutorials. Link to comment Share on other sites More sharing options...
UEZ Posted January 17, 2015 Share Posted January 17, 2015 (edited) You are welcome guys!PS: Bitshift to the right is also a division. In this case 4 bits to the rights means divison with 2^4 Br,UEZ Edited January 17, 2015 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
JohnOne Posted January 17, 2015 Share Posted January 17, 2015 You're not alone, I've read up about the bitwise operations many times, and just never got them at all. Morthawt 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. 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