Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@hex #4

Closed
majjam opened this issue Jun 21, 2013 · 7 comments
Closed

@hex #4

majjam opened this issue Jun 21, 2013 · 7 comments

Comments

@majjam
Copy link

majjam commented Jun 21, 2013

sorry for opening a new issue, but..
for me the already integrated hex support is missin the "0x" prefix.
The next thing is, that the "step" misses the << and >> operator.
At the moment I can only increment and decrement by stepsize like:

8
9
a
b

If you're using BIT operations on embedded devices it is very handy to use increment like
"Val << count" to select each bit itself. what results in:

01
02
04
08
10

Next thing is the prefix "0x" often it is necessary that you have the prefix "0x" at hex numbers. Then the compiler knows that hex values are meant meant.

0x01
0x02
0x04
0x08
0x10

I don't want to annoy you just want to give you my point.
If you have very small and fast communication, sometimes you en/decode states to single bits See example at the end.

if(MyVariableNo1beforeComLayer) myComBite1 |= 0x01
if(MyVariableNo2beforeComLayer) myComBite1 |= 0x02
if(MyVariableNo3beforeComLayer) myComBite1 |= 0x04
if(MyVariableNo4beforeComLayer) myComBite1 |= 0x08
if(MyVariableNo5beforeComLayer) myComBite1 |= 0x10

----dataBus----->

if(myComBite1 & 0x01) myVariableNo1BehindComLayer = 1;
if(myComBite1 & 0x02) myVariableNo2BehindComLayer = 1;
if(myComBite1 & 0x04) myVariableNo3BehindComLayer = 1;
if(myComBite1 & 0x08) myVariableNo4BehindComLayer = 1;
if(myComBite1 & 0x10) myVariableNo5BehindComLayer = 1;

best regards
Max

@jbrooksuk
Copy link
Member

Okay, I see what you're after now. Sorry for closing your other issue.

How do you imagine the syntax to work? If I can implement it into the current version, then I'll try my best to get it into #2 at the same time.

@jbrooksuk
Copy link
Member

Okay, this was a quick hack and my knowledge of hex is pretty limited. Could you try out the latest commit db1421f

The syntax is 0x1 << 1 or 0x100 >> 1 so you can do 0x256 << 2 and you'll get 0x1024 back.

I have limited knowledge of hex, but it seems to be working.

Also, I've not updated the README file to portray these changes yet, I would like further testing :)

@majjam
Copy link
Author

majjam commented Jul 10, 2013

sorry for the late answer,
Had holidays in France with my girl friend ;)
I think the syntax looks good.

I will check that next week and give you some feedback
thanks for your effort

@jbrooksuk
Copy link
Member

No worries, I hope you had a good holiday buddy.

Once you've checked it over, I'll merge the two hex languages so you can optionally supply 0x or use << and >> as the step argument.

@jbrooksuk
Copy link
Member

@majjam have you had a chance to look at this yet? From my quick tests it looks like it's working okay, in which case I'll merge the syntaxes.

If I hear nothing in the next couple of days I'll go ahead and merge.

@majjam
Copy link
Author

majjam commented Jul 22, 2013

somehow the code from yousn good for me, so i changed it to my intension:

Example 1 :

syntax : 0x1 <<2 6

0x1 starting number in hex (eg 0x50 is 80 in dec)
<<2 shift by two bits upwards
6 Padding

0x000001
0x000004
0x000010
0x000040
0x000100
0x000400
0x001000
0x004000
0x010000

Example 2 :

syntax : 0x1 2 5

0x01 starting number in hex (eg 0x50 is 80 in dec)
2 increment by two
5 Padding

0x00001
0x00003
0x00005
0x00007
0x00009
0x0000b
0x0000d
0x0000f
0x00011

Example 2 :

0x80 >>1 1

0x80 starting number in hex (eg 0x80 is 80 in dec)
<<1 shift by two bits upwards
1 Padding

0x80
0x40
0x20
0x10
0x8
0x4
0x2
0x1
0x0

---------------------------------------------code-------------------------------------------------------------------------
elif current[0] == '0' and current[1] == 'x':
#current = int(current[2:])
current = int(current,16)
padding = int(padding)

        def tick(counter):
            if(step.isdigit()):
                return str("0x%0*x" % (int(padding),int(current) + (counter)))
            elif(step[0] == '<') and (step[1] == '<'):
                return str("0x%0*x" % (int(padding),int(current) << (counter)))
            elif(step[0] == '>') and (step[1] == '>'):
                return str("0x%0*x" % (int(padding),int(current) >> (counter)))



    else:
        return

    # Do the stuff
    counter = 0
    for region in self.view.sel():
        self.view.replace(edit, region, tick(counter))
        if((step[0] == '<') and (step[1] == '<')) or ((step[0] == '>') and (step[1] == '>')):
            step2=step[2:]
            step2=int(step2,16)
            counter += int(step2)            
        else:
            counter += int(step)

@FichteFoll
Copy link
Member

Added in 2.0.0. (a22af2b)

Check the examples in the readme on how to do this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants